Company: Microsoft_6Aug
Difficulty: medium
Maximum Operations on String Problem Description Given a string s of lowercase English characters, the following operation can be performed any number of times: Choose an index i (0-based) such that 0 <= i <= n-3 , where n is the length of s . Let the three consecutive characters be s[i] , s[i+1] , s[i+2] . If s[i] == s[i+1] and s[i+1] != s[i+2] , then replace s[i+2] with s[i] . Find the maximum number of operations that can be applied to s . Input The first line contains the string s . Output Print a long integer representing the maximum number of times the operation can be applied. Examples Example 1 Input: accept Output: 3 Explanation: Start at i = 1 , substring "cce". Since s[1] == s[2] and s[1] != s[3] , replace s[3] with s[1] . New string: "acccpt" . Start at i = 2 , substring "ccp". Replace s[4] with s[2] . New string: "acccct" . Start at i = 3 , substring "cct". Replace s[5] with s[3] . New string: "accccc" . No