FunctionRacerProblemsRace

Meeting Rooms by Number

MediumClassesPython, JavaScript, TypeScript, Java, C++

Implement a class RoomBooker for k meeting rooms numbered 1 to k. A booking holds a room from start up to, but not including, end, so a meeting that ends at 5 does not clash with one that starts at 5. Write these methods:

room is always between 1 and k. The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

RoomBooker(2)
book(1, 5) returns 1
book(3, 7) returns 2
book(5, 6) returns 1
book(2, 4) returns -1
rooms_in_use(5) returns 2
cancel(1, 1) returns true
book(2, 4) returns 1
bookings_of(1) returns [[2,4],[5,6]]

The meeting from 5 to 6 fits in room 1 because the first meeting there ends exactly at 5. The meeting from 2 to 4 clashes in both rooms until the first booking of room 1 is cancelled.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems