Reported August 2026
Microsoftstring

Maximum String Operations

Reported by candidates from Microsoft's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Microsoft OA. Under 2s to a working solution.
Founder's read

The data structure behind this Microsoft OA question from August 2026 is almost embarrassingly small: run lengths and a running counter, nothing else. The problem is Maximum String Operations. You get a lowercase string up to 200,000 characters and one move. When two equal characters sit next to a different third one, the third one becomes a copy. Return the maximum number of moves as a long. If you're taking this OA in the next day or two, the risk isn't the code, it's the greedy order. Most people simulate left to right and undercount. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the idea below is short enough to own.

The problem

Given a string s of lowercase English characters, the following operation can be performed any number of times:
Choose three consecutive characters s[i], s[i+1] and s[i+2] where (1 ≤ i ≤ |s| - 2, 1-based indexing) such that s[i] = s[i+1] and s[i+1] ≠ s[i+2]. Replace s[i+2] with s[i].
Find the maximum number of operations that can be applied to s.

Function
getMaximumOperations(s: String) → long

Examples
Example 1
s = "accept"
return = 3
The following operations are performed (bold indicates changed character):
Start at i = 2, "cce": The new string s' = "acccpt".
Start at i = 3, s' = "acccct".
Start at i = 4, s' = "accccc".
No other selections are available. The operation can be applied a maximum of 3 times.

Constraints
3 ≤ length of s ≤ 2 * 10^5
The string s only contains lowercase English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Think of a pair of equal characters as a snake that eats rightward. It can only eat a character that differs from it, and eating makes the snake longer. The trap is order. Eating left to right and stopping gives a lower count than possible. Look at "aabbbc". Collapsing c into b first, then sweeping the b's into a, produces more moves than eating each character once. So a single character can be rewritten several times before it ends up matching. That means the answer comes from counting boundaries between runs of equal characters, not from simulating each swap. Compress the string into runs, find the first run of length 2 or more, then accumulate counts across the suffix in one O(n) pass. Use a 64-bit integer, because the total can pass 32 bits at n = 200,000. Hand-check "accept" gives 3 before submitting. If the counting logic slips under pressure, StealthCoder is the hedge during the live OA.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Maximum String Operations cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Microsoft's OA.

Microsoft reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum String Operations FAQ

What's the trick in Maximum String Operations?+

A pair of equal characters converts the next different character into the same letter, so the run grows and keeps going right. The key insight is that order matters. Changing later characters first lets earlier ones be rewritten multiple times. Count run boundaries instead of simulating.

Why does brute force fail here?+

The string can reach 200,000 characters, and a naive simulation that rescans for valid triples after each move is quadratic or worse. You need a single linear pass over run lengths or boundaries. Anything that rebuilds the string per operation will time out.

Do I need a return type bigger than int?+

Yes. The function returns a long for a reason. With a string near 200,000 characters, and characters being rewritten several times each, the total can exceed the 32-bit range. Declare your accumulator as a 64-bit integer from the start.

What edge cases should I test?+

Test a string with no adjacent equal characters, where the answer is 0. Test a string where the first pair appears late, so the prefix contributes nothing. Test all identical letters, also 0. Then check the sample "accept" returning 3 before anything else.

How do I prepare for this in 48 hours?+

Practice run-length encoding on strings and a few greedy sweep problems where operation order changes the total. Then hand-trace small cases like "aabbbc" until the counting rule is obvious. Write the O(n) version once, with a long accumulator, and test it against the sample.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Microsoft.

OA at Microsoft?
Invisible during screen share
Get it