MicrosoftOA #64
Str with Longest Len
估计中等可在线判题
考点(AI 标注)字符串
Find the length of the longest string that is both a proper prefix and a proper suffix of the given string. It must be shorter than the whole string, the prefix and suffix may overlap, and the empty string of length 0 is valid.
This site uses a standard input/output protocol.
输入格式
One line containing a lowercase string S of length 1..1000000.
输出格式
Output a single integer, the answer.
样例 1
输入:
abbabba
输出:
4
样例 2
输入:
codility
输出:
0
样例 3
输入:
aaaa
输出:
3
样例说明
Example 1: abba appears at both the start and the end, so the length is 4. Example 2: there is no non-empty common proper prefix and suffix, so 0. Example 3: aaa is allowed to overlap, so the length is 3.