cswork / OA打开练习工作台

AmazonOA #3

Self-Sufficient Substring

估计困难可在线判题

考点(AI 标注)哈希计数双指针滑窗

Find the longest non-empty contiguous substring that is not the whole string such that, for every character appearing in it, all occurrences of that character in the original string lie inside the substring. If none exists, output 0.

输入格式

One line containing a string of lowercase English letters, of length 1..100000.

输出格式

Output a single integer, the answer required by the problem.

样例 1

输入:

abadgdg

输出:

4

样例 2

输入:

aaaaaaa

输出:

0

样例 3

输入:

abac

输出:

3

样例说明

Example 1: the substring dgdg contains every d and g of the original string and has length 4, and there is no longer self-contained proper substring. Example 2: any self-contained substring that contains a must contain all 7 a's, which conflicts with being a proper substring, so the output is 0. Example 3: aba contains every a and b, so the length is 3.