Max Consecutive Ones II
A medium-tier problem at 52% community acceptance, tagged with Array, Dynamic Programming, Sliding Window. Reported in interviews at Yandex and 0 others.
Max Consecutive Ones II is the problem where you flip at most one zero to get the longest run of ones in a binary array. It's asked at Yandex and sits at 51% acceptance, which means half the candidates miss the sliding window trick on first attempt. You either nail the window logic or you spin on brute force and burn time. If this hits your live OA and the greedy approach feels wrong, StealthCoder surfaces the working solution in seconds, invisible to the proctor.
Companies that ask "Max Consecutive Ones II"
Max Consecutive Ones II is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.
Get StealthCoderThe trap is trying to maximize greedily without tracking state. The real pattern is a sliding window that expands right, counts zeros, and shrinks left when you hit two zeros. You keep the window that contains exactly one zero (or zero zeros), and the longest such window is your answer. Most candidates overthink with DP or iterate multiple times through the array. The insight is that you only need one pass with two pointers. Array, Dynamic Programming, and Sliding Window are all in the topic pool, but Sliding Window is the intended path. Even if you haven't seen this exact constraint before, StealthCoder gives you the working implementation during the assessment when your brain hits the wall.
Pattern tags
You know the problem.
Make sure you actually pass it.
Max Consecutive Ones II recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Max Consecutive Ones II interview FAQ
Is this easier or harder than the original Max Consecutive Ones?+
Significantly harder. The original is just counting. This one adds the flip constraint, which forces you to track state and manage window boundaries. That's why acceptance drops to 51%. The DP and sliding window angles both work, but sliding window is faster and less error-prone.
What's the trick most people miss?+
They try to expand right, flip a zero, then expand again without properly shrinking when they hit a second zero. The window contract logic is the crux. You need a two-pointer approach that maintains a valid window containing at most one zero at all times.
Does Yandex ask harder variants of this?+
Yandex is the only company reporting this in the data, so we can't generalize. But the medium difficulty suggests the variant here is the standard ask. Be ready for follow-ups on flip count limits or multiple passes, but solve this base case first.
Should I use DP or sliding window?+
Sliding window is cleaner and O(n) time, one pass. DP works but is slower to code and easier to mess up under pressure. For a live OA, sliding window with two pointers is the hedge. Master both, but practice sliding window until it's muscle memory.
How much time should this take in an interview?+
If you know the sliding window pattern, 10 to 15 minutes to code and test. If you're feeling it out, 25 to 35 minutes. At 51% acceptance, expect this to be a medium-hard filter. Time pressure is real. StealthCoder is your safety net if you blank on the window contract logic.
Want the actual problem statement? View "Max Consecutive Ones II" on LeetCode →