Inputs have the documented types. Times, capacities, seat requests, and counts are integers. Room and booking IDs are case-sensitive strings. Each returned list/dictionary must be a detached snapshot, and instances must be independent. Time is an abstract coordinate; no clock, time zones, recurrence, or elapsed-time cleanup is used.

Prototype: implement RoomCalendar():

  • reserve(start, end) -> bool: start >= 0 and end > start are required, otherwise raise ValueError unchanged. Intervals are half-open. Return False on any overlap, otherwise append the interval and return True.
  • slots() -> list[tuple[int, int]]: return all accepted intervals sorted by start then end, as a fresh list. Repeating the same reservation overlaps and returns False.

Final: implement MeetingRoomBooking(rooms), where rooms is a dictionary {room_id: capacity}. Copy the dictionary. Empty catalogs are allowed; an empty room ID or capacity below 1 raises ValueError.

  • book(booking_id, start, end, seats, room_count=1) -> list[str] | None: require nonempty booking ID, start >= 0, end > start, seats >= 1, and room_count >= 1; otherwise raise ValueError before any other check. Each selected room must independently hold at least seats people. Choose exactly room_count available rooms by (capacity, room_id) ascending. Return their IDs in that order and commit them together. If too few rooms qualify, return None without reserving anything or consuming the ID.
  • A successfully used booking ID remains reserved for the instance's lifetime, including after cancellation. Repeating book with that ID returns None, even if arguments match; validation still happens first. A failed request's ID may be retried.
  • cancel(booking_id) -> bool: cancel all assignments for one active booking and return True. Missing or already cancelled bookings return False without changing other bookings.
  • allocation(booking_id) -> list[str] | None: return a fresh list of room IDs in the original selection order for an active booking. Missing or cancelled bookings return None.
  • schedule(room_id) -> list[dict]: unknown room raises ValueError. Return active reservations for that room sorted by (start, end, id) ascending. Each entry has exactly {"id": booking_id, "start": start, "end": end, "seats": seats}. A multi-room booking appears once in each assigned room's schedule.

Invalid and unsuccessful requests preserve all schedules and existing allocations. Run python main.py --stage prototype, then python main.py --stage final (the default). Edit only exercise.py.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.