As reported: Salesforce online assessment (Feb 2025), a single coding question.
You are given a string s. In one operation you choose an index i such that s[i] == s[i+1] and s[i+1] != s[i+2], and replace s[i+2] with s[i]. Return the maximum number of operations you can perform.
Example 1
s = "accept"
Output: 3
accept → acccpt → acccct → accccc.
Example 2
s = "aabaab"
Output: 2
Example 3
s = "aabba"
Output: 4
First use bb to turn the last a into b (aabbb), then the aa pair turns the three bs into a one by one.
Constraints: 1 ≤ s.length ≤ 10^5; lowercase English letters. The answer can exceed 32 bits.
Code runner format: one line: s as a JSON string. Implement maxOperations(s); the harness prints the count.