Bird
Raised Fist0
LLDsystem_design~20 mins

Hotel, Room, Booking classes in LLD - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Hotel Booking Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Identify the correct relationship between Hotel, Room, and Booking classes

Consider a system with three classes: Hotel, Room, and Booking. Which of the following best describes their relationship?

AA Booking contains multiple Hotels; each Hotel has one Room.
BA Hotel contains multiple Rooms; each Room can have multiple Bookings over time.
CA Room contains multiple Hotels; each Booking is linked to one Room.
DA Booking contains multiple Rooms; each Room belongs to multiple Hotels.
Attempts:
2 left
💡 Hint

Think about real-life hotels: one hotel has many rooms, and rooms can be booked multiple times.

Architecture
intermediate
2:00remaining
Choose the best class design for Booking to avoid double booking

Which Booking class design best prevents double booking of the same Room for overlapping dates?

ABooking stores roomId and a single date; system allows multiple bookings on the same date.
BBooking stores only roomId; no date information is stored.
CBooking stores startDate and endDate but no roomId; system assumes one room per hotel.
DBooking stores roomId, startDate, endDate; system checks existing bookings for overlaps before confirming.
Attempts:
2 left
💡 Hint

To avoid double booking, you must track both the room and the booking dates.

scaling
advanced
2:30remaining
Scaling the Booking system for thousands of hotels and millions of bookings

What is the best approach to scale the Booking system to handle millions of bookings across thousands of hotels?

AUse a distributed database sharded by hotelId and cache frequently accessed room availability.
BStore all bookings in a single database table without indexing for simplicity.
CUse local files on each server to store bookings to avoid database overhead.
DKeep all booking data in memory on one server to speed up access.
Attempts:
2 left
💡 Hint

Think about how to distribute load and speed up queries for large data.

tradeoff
advanced
2:00remaining
Tradeoff between consistency and availability in Booking system

In a distributed Booking system, what is the main tradeoff when choosing between strong consistency and high availability?

AStrong consistency may reduce availability during network partitions but prevents double bookings.
BHigh availability always guarantees no double bookings even with network failures.
CStrong consistency allows the system to ignore network partitions and always accept bookings.
DHigh availability means the system will reject all bookings during network issues.
Attempts:
2 left
💡 Hint

Consider what happens if parts of the system cannot communicate.

component
expert
3:00remaining
Design component interaction for booking a room in Hotel system

Which sequence correctly describes the interaction flow when a user books a room?

A1,3,2,4
B2,1,3,4
C1,2,3,4
D3,2,1,4
Attempts:
2 left
💡 Hint

Think about the logical order of actions from user input to confirmation.

Practice

(1/5)
1. Which class is primarily responsible for storing information about individual rooms in a hotel system?
easy
A. Room
B. Hotel
C. Booking
D. Guest

Solution

  1. Step 1: Understand the role of each class

    The Hotel class manages the overall hotel, Booking handles reservations, and Room stores details about each room.
  2. Step 2: Identify which class holds room details

    Since Room is designed to represent individual rooms, it stores room number, type, and availability.
  3. Final Answer:

    Room -> Option A
  4. Quick Check:

    Room class = stores room info [OK]
Hint: Room class holds room details, not Hotel or Booking [OK]
Common Mistakes:
  • Confusing Hotel with Room class
  • Thinking Booking stores room details
  • Assuming Guest class stores room info
2. Which of the following is the correct way to represent a Booking class constructor in Python that takes room, guest, and date as parameters?
easy
A. def __init__(self, room, guest, date):
B. def Booking(room, guest, date):
C. def __booking__(self, room, guest, date):
D. def init(self, room, guest, date):

Solution

  1. Step 1: Recall Python constructor syntax

    Python constructors use the special method __init__ with self as the first parameter.
  2. Step 2: Match the correct method signature

    def __init__(self, room, guest, date): correctly uses def __init__(self, room, guest, date): which is the standard constructor format.
  3. Final Answer:

    def __init__(self, room, guest, date): -> Option A
  4. Quick Check:

    Constructor = __init__ method [OK]
Hint: Python constructors always use __init__(self, ...) [OK]
Common Mistakes:
  • Using method name other than __init__
  • Omitting self parameter
  • Using class name as method name
3. Given the following code snippet, what will be the output?
class Room:
    def __init__(self, number):
        self.number = number
        self.is_available = True

class Booking:
    def __init__(self, room):
        self.room = room
        self.room.is_available = False

room101 = Room(101)
print(room101.is_available)
booking1 = Booking(room101)
print(room101.is_available)
medium
A. True\nTrue
B. False\nTrue
C. False\nFalse
D. True\nFalse

Solution

  1. Step 1: Check initial availability of room101

    When room101 is created, is_available is set to True, so first print outputs True.
  2. Step 2: Booking changes room availability

    Booking constructor sets room101.is_available to False, so second print outputs False.
  3. Final Answer:

    True\nFalse -> Option D
  4. Quick Check:

    Initial True, then set False by Booking [OK]
Hint: Booking sets room availability to False immediately [OK]
Common Mistakes:
  • Assuming availability stays True after booking
  • Confusing order of prints
  • Ignoring side effect on room object
4. Identify the error in the following Booking class code snippet:
class Room:
    def __init__(self, number):
        self.number = number
        self.is_available = True

class Booking:
    def __init__(self, room, guest):
        self.room = room
        self.guest = guest
    def book(self):
        if self.room.is_available:
            self.room.is_available = False
            print("Booking successful")
        else:
            print("Room not available")

room = Room(201)
booking = Booking(room)
booking.book()
medium
A. is_available should be a method, not attribute
B. Missing guest argument when creating Booking instance
C. book method should return a value
D. Room class is not defined

Solution

  1. Step 1: Check Booking constructor parameters

    Booking __init__ requires room and guest, but only room is passed when creating booking instance.
  2. Step 2: Identify missing argument error

    Omitting guest argument causes a TypeError at runtime.
  3. Final Answer:

    Missing guest argument when creating Booking instance -> Option B
  4. Quick Check:

    Constructor args mismatch = missing guest [OK]
Hint: Match all constructor parameters when creating objects [OK]
Common Mistakes:
  • Ignoring missing guest argument
  • Assuming book method must return value
  • Thinking is_available must be a method
5. You want to design a system where a Hotel manages multiple Rooms and allows Bookings only if rooms are available. Which design approach best supports scalability and maintainability?
hard
A. Make Booking class manage all Rooms and Guests directly, without Hotel involvement.
B. Store all booking data inside Room class only, without separate Booking class.
C. Have Hotel class contain a list of Room objects, and Booking class references Room and Guest; Hotel checks availability before booking.
D. Use a single class combining Hotel, Room, and Booking functionalities.

Solution

  1. Step 1: Analyze class responsibilities

    Hotel should manage Rooms, Booking should link Rooms and Guests, keeping clear separation.
  2. Step 2: Evaluate design for scalability

    Have Hotel class contain a list of Room objects, and Booking class references Room and Guest; Hotel checks availability before booking. cleanly separates concerns, allowing Hotel to check availability and Booking to handle reservations, supporting easy maintenance and scaling.
  3. Final Answer:

    Hotel manages Rooms; Booking references Room and Guest; Hotel checks availability -> Option C
  4. Quick Check:

    Separation of concerns = Have Hotel class contain a list of Room objects, and Booking class references Room and Guest; Hotel checks availability before booking. [OK]
Hint: Separate Hotel, Room, Booking roles for clean design [OK]
Common Mistakes:
  • Combining all logic in one class
  • Booking managing Rooms directly
  • Ignoring availability checks in Hotel