MicrosoftOA #6
Three Consecutive Replace — Max Operations
Estimated MediumJudge-ready
Choose three consecutive characters where the first two are equal and the third is different, and replace the third with the character of the first two. Each operation only replaces and never deletes. Find the maximum number of operations that can be performed. The original site's walkthrough shortened the string; this site keeps the original length.
Input
One line of 3..200000 lowercase English letters.
Output
Output a single integer, the answer.
Example 1
Input:
aabaab
Output:
2
Example 2
Input:
abc
Output:
0
Example 3
Input:
aab
Output:
1
Example notes
Example 1: in aabaab, first change the last b to a, then change the b at the third position to a, giving aaaaaa, for 2 operations.
Example 2: there is no pair of equal adjacent characters, so no operation is possible; the answer is 0.
Example 3: the only triple aa b changes b to a, so the answer is 1.
Editorial
Loading solution…