Stage 1 of 3: Fewest rooms
Background. A day's meetings need rooms. Every meeting runs from its start to its end, and a room holds one meeting at a time.
Implement rooms_needed(meetings) in rooms.py: return the fewest rooms that hold every meeting.
meetingsis a list of 0 to 50,000 meetings in any order. Each meeting is a pair(start, end)of whole numbers with0 <= start < end <= 1,000,000,000. The meetings in one call are all tuples or all two-item lists.- A meeting needs one room from
startup to, but not including,end. Two meetings overlap when each starts before the other ends. A meeting that ends attand one that starts attdo not overlap, so they can use the same room one after the other. - Two meetings with the same start and the same end are two meetings, and each needs its own room.
- Return, as an
int, the fewest rooms in which every meeting has one room for its whole time and no two meetings in a room overlap. An empty list needs0. - Each call must return within 1.5 seconds for 50,000 meetings.
Example
rooms_needed([(60, 90), (75, 120), (90, 105), (120, 150)]) # 2
(60, 90) and then (90, 105) can use one room, and (75, 120) and then (120, 150) the other. Two rooms are needed, since (60, 90) and (75, 120) overlap.
Notes
test_helpers.pyholds the timer the large tests run under, which prints the seconds each large call took, and the seeded days of meetings they use.- On the starter, all 14 tests in
tests/test_part1.pyfail.
Done when Submit goes green.
Constraints
- Python 3.12 standard library only
- Editable:
rooms.py - Read-only:
test_helpers.pyand alltests/test_*.pyfiles - Inputs are always valid: 0 to 50,000 meetings, each a pair of whole numbers with 0 <= start < end <= 1,000,000,000, all tuples or all two-item lists in one call
What comes after stage 1
The next stages open once the tests for the one before them pass. Each raises the bar, the way an interviewer does in the room.
- Stage 2: A room for every meeting. Say which room each meeting gets, using no more rooms than the day needs.
- Stage 3: Exactly x at once. Every stretch of the day when exactly a given number of meetings are running at once.
The files you get
- Yours to edit: rooms.py.
- Read-only: test_helpers.py.
- Tests you can read and run: tests/test_part1.py. Hidden tests run on Submit.
The round: no AI, an assistant that only answers
Google runs this round without AI. Here the closest format is answer-only: the assistant answers your questions and reviews your code when you ask, the way an interviewer would, and never writes a line of it. The interviewer asks about your decisions as you go, and the report states the format. You can switch to the agent format when you press Begin.
Frequently asked, briefly answered
Is Meeting Rooms free?
It is a Pro problem. Free plan includes one complete problem, plus the first stage of several more, so you can see how a round works before you pay.
Which company asks something like this?
Google. It is modelled on Google's coding round, which runs without AI. Based on candidates' reports of Google interviews. Nyrion wrote this version, so the question you get may differ.
Do I bring my own AI tool?
No. The real round has no AI, so this one opens answer-only: an assistant that answers your questions and can't write code. You can switch to an agent that proposes changes when you press Begin.
What does the interviewer ask?
6 questions along the way about your own code, and one at the end about the whole session. A weak answer gets one follow up. The answers go into the report, which ends with a hire or no hire verdict.
Start the problem
Sign in and the problem opens where you left it. New here? An account takes a minute to create, and the Pro plan starts at the first stage of this problem.
More like it: every practice problem, Google's interviews, the AI coding interview guide.