← 返回 atlassian 的题目列表Expanding Tennis Club Court Assignment
类型:qbank
Given tennis-court bookings with start and finish times, assign each booking to a court so no court has overlapping bookings while using the minimum number of courts. Follow-ups add maintenance buffers and usage-based maintenance rules.
Requirements
Input is a list of booking records. A canonical shape is:
BookingRecord {
id: int
start_time: int
finish_time: int
}
assignCourts(List<BookingRecord> bookingRecords) -> List<Assignment>
Return a plan assigning every booking to a specific court.
A court can handle only one booking at a time.
Use the minimum number of courts when unlimited courts are available.
Follow-ups include:
After each booking, a fixed maintenance time X is required before the court can be reused.
Maintenance is required only after a court accumulates X amount of usage.
Notes
The base problem is interval partitioning; a min-heap keyed by each court's next available time is the natural fit.
Clarify interval semantics before coding: whether finish_time == next.start_time is reusable immediately, and how maintenance changes that boundary.
Preparation
Implement the heap version and a slower sweep-line version, then compare their output on the same test cases.
Add tests for back-to-back bookings, identical start times, nested intervals, and maintenance buffers.