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.
Examples
01 · Example 1
s = "accept" return = 3
:3
02 · Example 2
s = "aabaab" return = 2
:o
03 · Example 3
s = "aabba" return = 4
:)
More Salesforce problems
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Key Teams in TreeOA · Seen Mar 2026
- System Energy ReductionOA · Seen Mar 2026
- Update Logs by Symmetric XOROA · Seen Mar 2026
- Count Palindromic Concatenation PairsOA · Seen Mar 2026
- Collect Opportunity Data in a TreeOA · Seen Feb 2026
- Replace '?' to Avoid Adjacent DuplicatesOA · Seen Feb 2026
public int maxNumberOfOperations(String s) {
// write your code here
}
s"accept"
expected3
sign in to submit