Min Number of Chairs
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google's Min Number of Chairs problem is a simulation question that catches candidates off guard because it looks deceptively simple. You're tracking a sequence of entry and exit events, and you need to find the peak occupancy. The trap is thinking you need a complex data structure when really you just need to track state and count carefully. If you blank on the live OA, StealthCoder will read the problem and hand you the pattern in seconds.
Pattern and pitfall
This is a straightforward simulation. Parse events in order, increment a counter on entry, decrement on exit, track the maximum. The trick is handling edge cases: do entries and exits happen at the same timestamp, and which goes first. Most candidates over-engineer this, pulling in heaps or priority queues when they're not needed. The pattern is counting and state tracking, not dynamic programming or greedy. StealthCoder handles the implementation edge cases instantly if you're stuck during the real OA.
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 Min Number of Chairs 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
You've seen the question.
Make sure you actually pass Google's OA.
Google 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.
Min Number of Chairs FAQ
Is this a hard problem?+
No. It's a medium-level simulation. The challenge is not the algorithm but parsing the input correctly and handling timestamp collisions. If entries and exits occur at the same time, you need to know the tiebreaker rule.
Do I need a data structure?+
No. You need two variables: current_chairs and max_chairs. Iterate through events in order, update current based on entry or exit, track max. That's the whole solution.
What's the common mistake?+
Overthinking the tiebreaker. If someone enters at time T and another exits at time T, which happens first. Read the problem statement carefully. Also, forgetting to initialize max_chairs before the loop.
How do I prepare in 48 hours?+
Understand the problem statement fully. Walk through a small example by hand. Code it up in your preferred language. Test edge cases: all entries then all exits, all exits then all entries, single person.
Is this pattern still asked at Google?+
Yes. Google likes simulation problems because they test reading comprehension and implementation accuracy, not just algorithm knowledge. Expect them on entry-level and mid-level OAs.