#K92442. Room Reservation System

    ID: 38198 Type: Default 1000ms 256MiB

Room Reservation System

Room Reservation System

You are tasked with developing a room reservation system for a co-working space. The system should support two operations:

  1. Booking a room for a specific time interval.
  2. Cancelling an existing booking.

When a booking request is issued in the form:

book roomID startTime endTime

The system must add the booking only if there is no conflict with an existing booking in the same room. Two bookings for the same room are said to conflict if their time intervals overlap. In mathematical terms, given an existing booking with interval ([s, e)) and a new booking with (startTime) and (endTime), the bookings conflict if the following condition is not satisfied:

[ endTime \le s \quad \text{or} \quad startTime \ge e ]

Similarly, when a cancellation request is issued in the form:

cancel roomID startTime endTime

the system should remove the corresponding booking if it exists. For every operation, output a Boolean value indicating whether the operation was successful (i.e., "True" for success and "False" for failure).

inputFormat

Input is read from standard input. The first line contains an integer (T) representing the number of operations. Each of the following (T) lines contains an operation in one of the following formats:

book roomID startTime endTime
cancel roomID startTime endTime

where:

  • roomID is a string representing the room identifier,
  • startTime and endTime are integers representing the start and end times of the booking respectively.

outputFormat

For each operation, output either "True" or "False" (without quotes) on a separate line to indicate whether the operation was successful.

  • For a booking operation, output "True" if the room was successfully booked (i.e., no conflict exists) or "False" otherwise.
  • For a cancellation operation, output "True" if the booking existed and was cancelled successfully, or "False" if no such booking was found.## sample
6
book A 1 3
book A 2 4
book A 4 5
cancel A 1 3
cancel A 1 3
book A 2 4
True

False True True False True

</p>