← Atlassian Interview Insights
Classic interval scheduling problem but the assignment part tripped me up a bit.
Model the problem as an interval graph coloring problem where the minimum number of courts equals the maximum number of overlapping bookings. Use a sweep-line algorithm to compute the maximum overlap and then assign courts greedily by sorting bookings by start time and using a min-heap of end times to track available courts.
Pro tip: Clarify whether bookings are half-open intervals (e.g., [start, end)) to avoid edge cases, and mention that the greedy assignment is optimal because interval graphs are perfect. Also, discuss how to handle ties in start times by sorting by end time as a secondary key.
Ask whether intervals are inclusive or half-open, and confirm that bookings are fixed (no rescheduling). This avoids off-by-one errors and sets clear assumptions.
Create events for each start (+1) and end (-1), sort them, and track the running sum to find the maximum overlap. This gives the minimum number of courts required.
Sort bookings by start time. Use a min-heap to track the earliest end time among assigned courts. For each booking, if the earliest end time <= start, reuse that court; otherwise, allocate a new court.
Verify that no two bookings on the same court overlap and that the number of courts used equals the maximum overlap. Return the list of courts with their bookings.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.