Expanding Tennis Club (Interval Scheduling)
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)
Part (a)
Implement assignCourts to return a plan that assigns each booking to a specific court such that:
-
No court has overlapping bookings.
-
The total number of courts used is
minimized
.
Your output can be any structure that includes, for each booking, the assigned courtId.
Part (b) – maintenance buffer after each booking
After each booking on a court, the court requires a fixed maintenance time X (e.g., cleaning) before it can be used again.
-
If a booking ends at time
t
, the next booking on the same court cannot start before
t + X
.
Update the assignment logic accordingly.
Part (c) – maintenance only after some usage
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.
Notes
-
Times are integers.
-
You may assume
startTime < finishTime
.
-
State any additional constraints you rely on (e.g., max N).