Meeting Room Scheduler
medium · interval overlap, greedy room choice
Brief-reported interview attribution (unverified): Google, Amazon, Meta
How to approach an LLD roundDesign a meeting room scheduler. Rooms have capacities. A booking
is a half-open interval [start, end) in integer minutes: back-to-back meetings
(end == next start) are allowed, overlapping ones are not. find_room returns
the smallest room (by capacity) that is free for the interval and big enough;
ties break to the lowest room id.
class MeetingRoomScheduler:
def __init__(self):
def add_room(self, room_id, capacity):
def book(self, room_id, start, end, title):
# -> booking id (int, starting at 1), or None if the room is unknown,
# start >= end, or the interval overlaps an existing booking in that room
def cancel(self, booking_id):
# -> True if the booking existed, False otherwise
def bookings(self, room_id):
# -> [{"booking_id":, "start":, "end":, "title":}, ...] sorted by start
def find_room(self, start, end, min_capacity):
# -> room id, or None if no room fits
Rules. Overlap is start < existing_end and existing_start < end (half-open).
Booking ids start at 1 and increase. bookings returns entries sorted by start.
Tests use explicit inputs and injected clocks/callbacks. No network, real threads or application-server execution is involved.
Public demo
# Public demo: run after implementing the class API above.
m = MeetingRoomScheduler()
m.add_room('A', 4)
m.add_room('B', 10)
m.add_room('C', 6)
print(m.book('A', 60, 120, 'Standup'))Starter code
class MeetingRoomScheduler:
def __init__(self):
"""Initialize the state described in the problem."""
pass
def add_room(self, room_id, capacity):
"""Implement the return value and rules in the API contract."""
pass
def book(self, room_id, start, end, title):
"""-> booking id (int, starting at 1), or None if the room is unknown, start >= end, or the interval overlaps an existing booking in that room"""
pass
def cancel(self, booking_id):
"""-> True if the booking existed, False otherwise"""
pass
def bookings(self, room_id):
"""-> [{"booking_id":, "start":, "end":, "title":}, ...] sorted by start"""
pass
def find_room(self, start, end, min_capacity):
"""-> room id, or None if no room fits"""
pass
Each test has a five-second execution limit. Your practice drafts and solved progress stay in this browser.
Return to the Python compiler