FastPrepFastPrep
Problem Brief

Longest Cipher (Intuit India)

INTERNOA

You are working on a secret government project, and you 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 s consisting of n alphanumerical characters. You need to find the longest substring of s that is a valid cipher and return its length. A substring is defined as a contiguous segment of a string.

For example, given "k3Cb", the substrings that are valid ciphers are "C" and "Cb". Note that "kCb" is not a substring, and "k3B" is not a valid cipher. In this case, your function should return 2 as the longest substring is "Cb". Alternatively, given "k3uu", your function should return -1 since there is no substring that satisfies the restrictions on the format of a valid cipher.

Input

The input contains a string s.

Output

Print the length of the longest substring that is a valid cipher. If there is no such substring, your function should return -1.

1Example 1

Input
s = "a2Bac"
Output
3
Explanation

The three valid ciphers are {B, Ba, Bac}, so the output is the length of "Bac," which is 3.

2Example 2

Input
s = "aA0bCbd"
Output
4
Explanation

The valid ciphers are {A, AE, bC, bCb, bCbd, C, Cb, Cbd}, so the output is 4.

Constraints

Limits and guarantees your solution can rely on.

1 ≤ n ≤ 200
s consists only of alphanumerical characters (a-z and/or A-Z and/or 0-9).
public int longestCipher(String s) {
    // write your code here
}
Input

s

"a2Bac"

Output

3

Sign in to submit your solution.