FunctionRacerProblemsRace

Booking Log

HardClassesPython, JavaScript, TypeScript, Java, C++

Implement a class BookingLog for a hall that takes any number of bookings at once and wants to know how crowded it gets. A booking from start to end covers every moment from start up to, but not including, end. Write these methods:

The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

BookingLog()
book(1, 4) returns 1
book(2, 6) returns 2
book(4, 8) returns 2
count_at(4) returns 2
cancel(1, 4) returns true
get_busiest() returns 2
cancel(1, 4) returns false

The first two bookings share the moments 2 and 3. The third one starts at 4, exactly when the first one ends, so they do not overlap, but it overlaps the second. After the cancel only two bookings are left and they still share moment 4.

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