Reported March 2024
Googlegreedy

Min Flips

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 asked this in March 2024 and it's a bit of a sleeper. You get a binary string or array, and the goal is to flip the minimum number of bits to reach some target state. Usually that means making all bits the same (all 0s or all 1s) or satisfying a constraint like no consecutive 1s. The pattern is greedy with a touch of observation. StealthCoder can feed you the approach in real time if you freeze on the greedy choice.

Pattern and pitfall

The trick is recognizing that you don't need to try every possible flip combo. Greedy works: scan left to right, and whenever you see a violation of the target state, flip that bit and count it. For 'all same' variants, calculate the cost both ways (flip all 0s to 1, flip all 1s to 0) and return the min. The pitfall is overthinking it as DP when it's really just a single pass. If the constraint is about consecutive 1s or other local rules, the same greedy sweep applies. StealthCoder spots the pattern instantly if you're stuck between greedy and DP.

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 Min Flips 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

⏵ The honest play

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

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

Min Flips FAQ

Is this actually greedy or is it a DP problem?+

It's greedy. You scan once, make a local optimal choice at each step (flip or don't flip based on current state and target), and that builds the global min. DP is overkill and a common trap. Trust the single pass.

What if the problem asks for all 0s or all 1s? Do I run the algorithm twice?+

Yes. Calculate the cost to flip everything to 0, then to 1, and return the minimum. It's two quick passes or a single pass tracking both counters. Either way, constant space.

Does bit order or position matter?+

Not for 'all same' variants. Order matters only if the constraint involves adjacent bits, like no consecutive 1s allowed. Then you process left to right and decide flip based on what came before.

How do I prep for this in 48 hours?+

Understand what the target state is by reading the full problem carefully. Then sketch a greedy pass on paper with a small example. Once the pattern clicks, code it. Don't memorize; practice the observation step.

Is this question still common at Google?+

Bit manipulation and greedy problems show up regularly at Google. This specific variant has been reported recently. It's not the hardest OA question, but it catches people who default to DP without thinking.

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