Problem · String
Max Number of Operations
Learn this problemProblem statement
Given a string s, choose 3 consecutive characters s[i], s[i+1], s[i+2]. Replace s[i+2] with s[i] if s[i]=s[i+1] and s[i+1]≠s[i+2]. Find the maximum number of operations that can be performed on s.
Function
maxNumberOfOperations(s: String) → intExamples
Example 1
s = "accept"return = 3:3
Example 2
s = "aabaab"return = 2:o
Example 3
s = "aabba"return = 4:)