Max Consecutive ON Servers
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon's Max Consecutive ON Servers problem hit the OA circuit in July 2024, and it's a sliding window trap disguised as a simple scan. You're given a list of server states (on/off) and need to find the longest sequence of consecutive ON servers. Sounds trivial until edge cases and large arrays enter. StealthCoder handles the moments when you second-guess your window bounds or forget to track the max correctly.
Pattern and pitfall
This is a textbook sliding window problem, but the real trick is knowing when to shrink versus when to expand. You maintain a window of consecutive ON servers and track its maximum width. The gotcha: many candidates try to use a two-pointer approach and mess up the shrinking logic when they hit an OFF server. The correct move is to expand right, and the moment you see an OFF, you either shrink from the left or reset the window entirely. Some solutions reset on every OFF (simpler, O(n) time); others use a true sliding window with a pointer. Both work. The pattern is almost always sliding window, occasionally disguised as prefix sums or memoization if the problem scales to variants.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Max Consecutive ON Servers 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as max consecutive ones. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Max Consecutive ON Servers FAQ
Is this really just 'find the longest run of 1s in an array'?+
Yes. Don't overthink it. The problem wraps it in server metaphor. You track consecutive ONs, store the max length, and return it. One pass, O(n) time, O(1) space.
What's the gotcha Amazon likes here?+
Off-by-one errors in window reset and candidates forgetting to update the max before shrinking. Also, some try DP when sliding window is instant. Practice the reset logic in your prep.
Do I need two pointers or just a single counter?+
A single counter is cleaner. Increment for each ON, reset to 0 on OFF, update max as you go. Two-pointer window is overkill here and introduces bugs.
Will Amazon ask follow-ups like 'what if servers reset after X minutes'?+
Possibly. But nail the base problem first. If a follow-up comes, it's usually a math or state-machine twist, not a new algorithm.
How much time do I have to solve this live?+
Typically 15-20 minutes for this tier. Write the simple solution, test three cases (empty, all ON, all OFF), and move on. Don't gold-plate.