Reported June 2024
Googlegreedy

Max Subarray Filled with Zeros

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

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

Google's June OA included a question about finding the maximum subarray filled with zeros. This is a classic max subarray variant where you're hunting for the longest contiguous stretch of zeros, not maximizing sum. It sounds simple until you realize the trick: you're not just counting. You're applying Kadane's algorithm logic to a binary lens, which means tracking state across the array and resetting when the pattern breaks. StealthCoder reads the exact wording and flags whether you need the subarray itself, its length, or its indices before you write a single line.

Pattern and pitfall

The core pattern here is a sliding window or prefix-sum approach disguised as a max subarray problem. You iterate through the array, track the current run of consecutive zeros, and keep a running maximum. The catch is that many candidates overthink it and try to apply full Kadane's algorithm when a single pass with two pointers or a counter is enough. The pattern is fundamentally greedy: as soon as you hit a non-zero, you close the window, compare, and reset. Edge cases matter: empty arrays, no zeros at all, zeros only. StealthCoder acts as your safety net during the OA if you freeze on the implementation details or forget to handle boundaries.

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 Max Subarray Filled with Zeros 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

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as max consecutive ones. If you have time before the OA, drill that.

⏵ The honest play

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

Google 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.

Max Subarray Filled with Zeros FAQ

Is this really just counting consecutive zeros?+

Yes and no. You count, but you also need to track the start and end indices or return the length. The trick is resetting your counter when you hit a non-zero and comparing against a global max each time. It's O(n) with one pass.

What if the entire array is zeros?+

Your max subarray is the whole array. Your counter never resets, and you return its final length or the range [0, n-1]. Test this case before you submit.

Do I need to handle negative numbers or just 0 and 1?+

The problem says 'filled with zeros,' which implies you're looking for runs of exactly zero. Any non-zero value breaks the run. Clarify the input range in the OA, but assume 0 is the only target value.

Is this a hash-table or sorting problem?+

No. It's a single-pass greedy problem, sometimes categorized as a sliding window variant. No sorting, no extra space needed beyond a couple of counters. O(n) time, O(1) space.

How do I prepare for this in 48 hours?+

Understand Kadane's algorithm at a high level, then code a simple 'max consecutive zeros' function from scratch twice. Test with edge cases: empty, all zeros, no zeros, single zero. Speed matters more than elegance here.

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

OA at Google?
Invisible during screen share
Get it