AmazonOA #319
Optimized Identifiers
估计中等可在线判题
In each step, delete the first or the last character of the current string. The type of a string is its first character followed by its last character; a single character a has type aa, and the empty string has an empty type. Only the final type must equal the initial type; it may differ temporarily along the way. Find the maximum number of deletions.
输入格式
One line containing a lowercase string s; the original bounds are 2≤|s|≤200000.
输出格式
Output a single integer, the answer.
样例 1
输入:
babdcaac
输出:
5
样例 2
输入:
axxbab
输出:
4
样例 3
输入:
aba
输出:
2
样例说明
The answers are 5, 4 and 2. The output 0 of 319's original example babdcaac conflicts with the conclusion 5 in that example's own explanation and with 318, the complete version of the same problem; this site openly corrects it to 5 and binds both raw sources. The type of hchc should be hc, not h. The 318 source only looks at the first occurrence of the last character, so it misses shorter valid ranges further on.