Maximum Number of Operations on String
Given a string s of lowercase English characters, the following operation can be performed on it any number of times.
- Choose three consecutive characters s[i], s[i+1] and s[i+2] where (1 ≤ i ≤ |s| - 2, 1-based indexing) such that s[i] = s[i+1] and s[i+1] ≠ s[i+2]. Replace s[i+2] with s[i].
- For example, if s = "aabc", then after the operation at i = 1, s = "aaac".
Find the maximum number of operations that can be applied to s.
Complete the function maximumNumberOfOperations in the editor.
maximumNumberOfOperations has the following parameter:
String s: the string to perform operations on
Returns
int: the maximum number of operations that can be applied
1Example 1
2Example 2
Constraints
Limits and guarantees your solution can rely on.
len of string can be up to 105