Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Longest Cipher You are working on a secret government project and are tasked with decoding. You hit upon a theory that the cipher is hidden
Longest Cipher
You are working on a secret government project and are tasked with decoding.
You hit upon a theory that the cipher is hidden within a sequence of characters and has the following restrictions:
a It has to contain at least one uppercase character.
b It cannot contain any digits.
You are given a string consisting of alphanumerical characters. You need to find the longest substring of and return its length. A substring is defined as a contiguous segment of a string.
For example, given kCb the substrings that are valid ciphers are C and Cb Note that is not a substring, and kB is not a valid cipher. In this case, your function should return as the longest substring is Cb Alternatively, given kuu your function should return since there is no substring that satisfies the restrictions on the format of a valid cipher.
Input
The input contains a string
Output
Print the length of the longest substring that is a valid cipher.
If there is no such substring, your function should return
Constraints
consists only of alphanumerical characters andor AZ andor
Example #
Input
aBac
Output
Explanation: The three valid ciphers are Bac so the output is the length of "Bac," which is
Example #
Input
aAObCbd
Output
Explanation: The valid ciphers are so the output is
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started