Problem · String

Max Number of Operations

Learn this problem
HardSalesforce logoSalesforceOA
See Salesforce hiring insights

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

drafts saved locally
public int maxNumberOfOperations(String s) {
  // write your code here
}
s"accept"
expected3
checking account