AmazonOA #155
Find the Longest Isolated Substring Length
Estimated HardJudge-ready
Topics (AI-labelled)StringsPrefix & Ranges
Find the longest non-empty contiguous substring such that none of its characters appears outside the substring, and the substring cannot equal the whole original string; if there is none, return 0.
Input
One line with a lowercase string of length 1..100000.
Output
Output a single integer answer.
Example 1
Input:
abcba
Output:
3
Example 2
Input:
amazonservices
Output:
11
Example 3
Input:
aaaa
Output:
0
Example notes
Example 1: in bcb, neither b nor c appears outside, so it is a proper substring of length 3; the source's 0 has been corrected. Example 2: zonservices has length 11, and outside it there are only a, m, a, which share no characters with it. Example 3: unless it is the whole string, any a inside appears outside as well, so there is no valid non-empty proper substring and the answer is 0.
Editorial
Loading solution…