FastPrepFastPrep
Problem Brief

Max Number of Operations

OA

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.

1Example 1

Input
s = "accept"
Output
3
Explanation
:3

2Example 2

Input
s = "aabaab"
Output
2
Explanation
:o

3Example 3

Input
s = "aabba"
Output
4
Explanation
:)
public int maxNumberOfOperations(String s) {
  // write your code here
}
Input

s

"accept"

Output

3

Sign in to submit your solution.