Reported September 2026
Amazonsliding window

Maximize Consecutive Equal Answers

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

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

Amazon reportedly served this one in September 2026, and the whole solution hinges on one structure: a window with two counters. That's it. Maximize Consecutive Equal Answers hands you a string of T and F plus a change budget, and asks for the longest stretch you can flip into a single letter. If your OA lands in the next day or two, this is a sliding window problem wearing a string costume. It's short once you see it and painful if you start with brute force on 200000 characters. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the pattern below is simple enough to carry in your head.

The problem

A string contains only T and F. You may change at most maxChanges characters. Return the maximum length of a contiguous substring that can be made entirely equal.

Function
maximizeConfusion(answers: String, maxChanges: int) → int

Examples
Example 1
answers = "TTFF"
maxChanges = 2
return = 4
Case 1 exercises the documented deterministic contract.
Example 2
answers = "TFFT"
maxChanges = 1
return = 3
Case 2 exercises the documented deterministic contract.
Example 3
answers = "TTFTTFTT"
maxChanges = 1
return = 5
Case 3 exercises the documented deterministic contract.

Constraints
1 <= answers.length <= 200000.
0 <= maxChanges <= answers.length.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: a window is valid if the count of the minority letter inside it is at most maxChanges. Track counts of T and F in the window. Expand right one character at a time. When min(countT, countF) exceeds maxChanges, shrink from the left until it's valid again. Record the max window length as you go. That's O(n) time and O(1) space. The common pitfall is running a nested loop over every start and end, which is O(n^2) and dies at length 200000. Another miss is handling maxChanges = 0, where the answer is just the longest run of identical letters. The window handles that naturally. You can also run the window twice, once per target letter, counting only the opposite letter. Both versions work. If you freeze live, StealthCoder can hand you the window skeleton, but you should be able to write it from this paragraph.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Maximize Consecutive Equal Answers 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as maximize the confusion of an exam. If you have time before the OA, drill that.

⏵ The honest play

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

Amazon reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximize Consecutive Equal Answers FAQ

What's the trick to Maximize Consecutive Equal Answers?+

Sliding window. Keep counts of T and F inside the window. The window is legal when the smaller count is at most maxChanges, since you'd flip the minority letter. Grow right, shrink left when illegal, track the best length. One pass, linear time.

How hard is this problem really?+

Medium at most. If you know sliding window, it's about ten lines. The difficulty is recognizing that you only need the minority count, not which characters to flip. Candidates who go brute force or DP overcomplicate it and time out.

Do I need to try both T and F as the target letter?+

Not if you track both counts and use the minimum. The minority count is exactly the number of flips needed to make the window uniform. Alternatively run two passes, one per letter, counting the opposite one. Both give the same answer.

What edge cases should I test before submitting?+

Test maxChanges = 0, where the answer is the longest run of one letter. Test maxChanges equal to the length, where the answer is the whole string. Test a single-character string. Also try an already-uniform string like all T. Those catch most off-by-one bugs.

How do I prepare for this in 48 hours?+

Write the sliding window template from memory a few times: expand right, shrink left while invalid, update best. Then solve two or three variants with a budget of changes. Focus on the invariant, not memorizing code. This pattern shows up repeatedly in Amazon-style assessments.

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

OA at Amazon?
Invisible during screen share
Get it