AmazonOA #252
Longest Perfect Anagrams
估计困难可在线判题
Two strings in which every character occurs the same number of times, but whose contents are not exactly the same, form a perfect anagram pair. Find the maximum length of two contiguous substrings of the original string that form such a pair; they may overlap, two positions with identical content do not count, and output −1 if no such pair exists.
输入格式
One line containing the string. 1≤length≤100000, lowercase letters.
输出格式
Output a single integer, the answer.
样例 1
输入:
abcacb
输出:
4
样例 2
输入:
cabcab
输出:
3
样例 3
输入:
aabbcc
输出:
-1
样例说明
The answers are 4, 3 and −1. In the first example bcac and cacb have length 4 and overlap, which is valid.