Booking Log
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:
BookingLog()starts with no bookings.book(start, end)adds a booking and returns the busiest count after it: the largest number of bookings that cover one and the same moment.cancel(start, end)removes one booking with exactly these times and returnsTrue. If there is no such booking, it changes nothing and returnsFalse. Equal bookings may exist several times, and only one of them is removed.count_at(moment)returns how many bookings covermoment.get_busiest()returns the busiest count as it is now,0with no bookings.
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
0 <= start < end <= 500 <= moment <= 50- Each test makes
1to40method calls after the constructor.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.