You run a tennis club with an unlimited number of courts. Each booking has a start and finish time.
class BookingRecord {
int id;
int startTime;
int finishTime;
}
List<Assignment> assignCourts(List<BookingRecord> bookingRecords)
Implement assignCourts to return a plan that assigns each booking to a specific court such that:
Your output can be any structure that includes, for each booking, the assigned courtId.
After each booking on a court, the court requires a fixed maintenance time X (e.g., cleaning) before it can be used again.
t
, the next booking on the same court cannot start before
t + X
.
Update the assignment logic accordingly.
Follow-up variant: maintenance is not required after every booking, but only after a court has accumulated a certain amount of usage (clarify with the interviewer whether this threshold is in number of bookings or total time used). Update the assignment approach to support this rule.
startTime < finishTime
.