Problem · String

Maximum String Operations

Learn this problem
HardAtlassian logoAtlassianFULLTIMEOA

Problem statement

Choose three consecutive characters whose first two are equal and whose third differs, then replace the third with the repeated character. Apply the operation any number of times and return the maximum possible operation count.

Function

getMaximumOperations(s: String) → long

Examples

Example 1

s = "accept"return = 3

The pair cc can successively absorb e, p, and t.

Example 2

s = "aabaab"return = 2

Two differing characters can be changed by the available repeated-a pairs.

Constraints

  • 3 <= s.length <= 200000
  • s contains lowercase English letters.

More Atlassian problems

drafts saved locally
public long getMaximumOperations(String s) {
  // Write your code here.
}
s"accept"
expected3
checking account