FastPrepMax Number of Operations

Max Number of Operations

Salesforce logoSalesforce● HardOA
Learn

Problem 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) → int

Examples

Example 1

s = "accept"return = 3

:3

Example 2

s = "aabaab"return = 2

:o

Example 3

s = "aabba"return = 4

:)

More Salesforce problems

See Salesforce hiring insights
public int maxNumberOfOperations(String s) {
  // write your code here
}
s"accept"
expected3
Checking account…