cswork / OAOpen practice workspace

IntuitOA #16

Longest Cipher (Intuit India)

EasyJudge-ready

Topics (AI-labelled)Two PointersStrings

Find the longest contiguous substring that contains no digits and at least one uppercase English letter; output -1 if no such substring exists.

Input

A single line containing a string of only a-z, A-Z, and 0-9, with 1≤length≤200.

Output

Output the answer as described; for array answers, separate values with spaces.

Example 1

Input:

k3Cb

Output:

2

Example 2

Input:

k3uu

Output:

-1

Example 3

Input:

aB2CD

Output:

2

Example notes

Digits split the string into letter-only segments; only segments that contain an uppercase letter are valid.

Correctness: no valid substring can cross a digit, so it lies entirely within one letter segment delimited by digits; it suffices to check whether each segment contains an uppercase letter.

Complexity: O(n) time, O(1) space.

Editorial

Loading solution…