Design a Hotel Management System
🏨 What is a hotel management system? It is the software at the front desk of a hotel. It knows every room and what it costs per night. Guests reserve a room for some dates, check in when they arrive, run up extras like room service during the stay, and pay one bill when they check out.
This problem looks like the flight booking problem with beds instead of seats, but one detail changes the core of the design: a hotel room is sold by the night, not once. The same room is booked by many guests over the year, so "is this room free?" only makes sense together with "for which nights?". On top of that, a reservation lives through several stages (reserved, checked in, checked out, or cancelled), and the bill grows during the stay. Those three ideas (date ranges, a lifecycle, a bill) are what the interviewer is testing.
Requirements
"Design a hotel management system. Guests can reserve rooms, check in, check out and pay their bill."
Here are the questions that change the design, and the answers we will code against.
Clarifying Questions
You: What kinds of rooms are there, and how are they priced?
Interviewer: Singles, doubles and suites. Each room has its own nightly rate; a corner suite can cost more than the suite next to it.
You: How do dates work? If a guest arrives on day 3 and leaves on day 5, which nights do they use?
Interviewer: Nights 3 and 4. They leave on the morning of day 5, so another guest can arrive in that room on day 5. Use plain day numbers.
You: When a guest reserves, do they get a specific room, or just a room type?
Interviewer: A specific room, chosen when they reserve: the lowest-numbered room of that type that is free for the whole stay.
You: What goes on the bill?
Interviewer: The nights times the room rate, plus extras added during the stay, like the minibar or room service. The front desk prints an itemized bill, so keep the lines.
You: Can a guest leave early, or late?
Interviewer: Early, yes: they pay only for the nights they stayed, at least one, and the room can be sold again from that day. Late check-out is not supported.
You: When can a guest check in, and when can they cancel?
Interviewer: Check-in only on the arrival day. Cancel any time before check-in, without a fee. Once they are in, they check out instead.
You: Do several front desks or a website take reservations at the same time?
Interviewer: Assume one at a time for now.
The second answer is the one that matters most. "Nights 3 and 4, and someone else can arrive on day 5" means a stay is a half-open range: it includes its first day and excludes its last. Getting that boundary wrong is the classic bug in this problem, and the tests check it.
💡 Interview tip: Whenever a problem books something over time (rooms, meeting rooms, rental cars), ask whether the end is included. Write the answer down as "from ≤ night < to" and use that exact comparison everywhere. Half-open ranges make back-to-back bookings work without any special case.
Final Requirements
- The hotel has rooms, each with a unique number, a type (
SINGLE,DOUBLE,SUITE) and a nightly rate. - A stay from day
fromto daytouses the nightsfrom, ..., to - 1. Two stays in the same room clash only if they share a night. - Anyone can ask which rooms of a type are free for a range of nights.
- A guest can reserve a room type for a range of nights. They get the lowest-numbered room of that type that is free for every night; if none is, the reservation fails.
- A reservation moves through
RESERVED → CHECKED_IN → CHECKED_OUT, orRESERVED → CANCELLED. Any other move is rejected. - Check-in is allowed only on the arrival day. Cancelling frees the room's nights.
- While a guest is checked in, the hotel can add extras (positive amounts) to their bill.
- At check-out on a day between arrival and the planned departure, the bill adds the room charge: nights stayed (at least one) times the rate. The system returns the total, and the room is free again from that day.
Out of scope
- Payments, deposits, taxes and cancellation fees.
- No-shows and late check-out.
- Housekeeping and maintenance (we come back to this in Extensibility).
- Several hotels, loyalty programs, and guest profiles beyond a name.
- Several front desks at the same time (also in Extensibility).