Inputs have the documented types. Times, capacities, seat requests, and counts are integers. Room and booking IDs are case-sensitive strings. Each returned list/value record 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 >= 0 and end > start are required, otherwise raise std::invalid_argument unchanged. Intervals are half-open. Return false on any overlap, otherwise append the interval and return true.
  • slots(): 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 value record the fields declared in the value record below. Copy the value record. Empty catalogs are allowed; an empty room ID or capacity below 1 raises std::invalid_argument.

  • book(): require nonempty booking ID, start >= 0, end > start, seats >= 1, and room_count >= 1; otherwise raise std::invalid_argument 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 nullopt 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 nullopt, even if arguments match; validation still happens first. A failed request's ID may be retried.
  • cancel(): cancel all assignments for one active booking and return true. Missing or already cancelled bookings return false without changing other bookings.
  • allocation(): return a fresh list of room IDs in the original selection order for an active booking. Missing or cancelled bookings return nullopt.
  • schedule(): unknown room raises std::invalid_argument. Return active reservations for that room sorted by (start, end, id) ascending. Each entry has exactly the fields declared in the value record below. A multi-room booking appears once in each assigned room's schedule.

Invalid and unsuccessful requests preserve all schedules and existing allocations.

The public C++ API below is authoritative for field types and return values. erase is used where another language might use a method named delete, because delete is a C++ keyword. Returned records are value snapshots with the documented named fields; mutating a record or its nested vectors cannot affect the service.

cpp
struct Reservation {std::string id;Int start,end,seats;bool operator==(const Reservation&)const=default;};
class RoomCalendar { public:
 RoomCalendar();
 bool reserve(Int start,Int end);
 Vec<Pair> slots() const;
};
class MeetingRoomBooking { public:
 explicit MeetingRoomBooking(std::map<std::string,Int> rooms);
 Opt<Strings> book(const std::string& id,Int start,Int end,Int seats,Int room_count=1);
 bool cancel(const std::string& id);
 Opt<Strings> allocation(const std::string& id) const;
 Vec<Reservation> schedule(const std::string& room) const;
};

Compile and run from this directory:

Shell
c++ -std=c++20 -O2 -Wall -Wextra -pedantic -pthread main.cpp -o practice
./practice --stage prototype
./practice --stage final

Edit exercise.hpp. Both stages start unfinished and must report failures until implemented. Keep main.cpp as the executable contract. The runner returns nonzero for a failed check, an unexpected exception, an invalid stage, or an empty suite. C++20 and only the standard library are required.

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.

C++ runtime powered by Wasmer.