IntuitOA #16
Longest Cipher (Intuit India)
简单可在线判题
Find the longest contiguous substring that contains no digits and at least one uppercase English letter; output -1 if no such substring exists.
输入格式
A single line containing a string of only a-z, A-Z, and 0-9, with 1≤length≤200.
输出格式
Output the answer as described; for array answers, separate values with spaces.
样例 1
输入:
k3Cb
输出:
2
样例 2
输入:
k3uu
输出:
-1
样例 3
输入:
aB2CD
输出:
2
样例说明
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.