A neighborhood car wash has one washing bay. Customers request the bay for different time periods.
Implement the WashBaySchedule class to manage these reservations.
Each reservation uses the half-open time range [washStart, washEnd). The bay is occupied from washStart up to, but not including, washEnd.
true.false without saving it.WashBaySchedule()
Creates an empty schedule for the washing bay.
boolean reserve(int washStart, int washEnd)
washStart: The starting time of the requested reservation.washEnd: The ending time of the requested reservation.true if the reservation is accepted and saved.false if it overlaps an existing reservation.0 ≤ washStart < washEnd ≤ 1,000,000,0001,000 calls will be made to reserve.Constructor: WashBaySchedule bay = new WashBaySchedule()
Method Call: bay.reserve(washStart = 75, washEnd = 95)
Output: true
Method Call: bay.reserve(washStart = 40, washEnd = 75)
Output: true
Method Call: bay.reserve(washStart = 90, washEnd = 110)
Output: false
Method Call: bay.reserve(washStart = 95, washEnd = 130)
Output: true
The first request reserves the bay from time 75 until time 95. The second request ends exactly at time 75, so it is accepted.
The third request overlaps the first reservation between times 90 and 95, so it is rejected. The final request starts exactly when the first reservation ends, so it is accepted.