← Atlassian Interview Insights
I knew meeting-rooms II but for a second I started going down the path of just counting the max overlaps and forgot they wanted the actual mapping back.
Model the problem as an interval graph coloring problem where the minimum number of courts equals the maximum number of overlapping bookings. Sort bookings by start time and use a min-heap of court end times to assign each booking to an available court, reusing courts when possible and allocating new ones only when necessary.
Pro tip: Mention that the greedy algorithm is optimal because the maximum overlap gives a lower bound and the algorithm achieves it. Also, clarify that if the problem asks for the fewest courts, the number is fixed, but the assignment may vary; focus on producing a valid assignment with that minimum number.
Restate the problem: assign bookings to courts such that no two bookings on the same court overlap, using the fewest courts. Clarify input format, whether times are given as intervals, and if bookings are sorted.
Recognize this as interval graph coloring, where the minimum number of courts equals the maximum number of overlapping bookings. This equivalence is key to proving optimality.
Sort bookings by start time. Use a min-heap to track the end times of the last booking on each court. For each booking, if the earliest ending court is free (end time <= start time), assign it there and update the heap; otherwise, allocate a new court.
Write code to perform the assignment, ensuring correct handling of simultaneous start/end times (e.g., a booking ending at 10:00 and another starting at 10:00 do not overlap). Track court IDs and return the mapping.
State time complexity O(n log n) due to sorting and heap operations, and space O(n). Walk through a small example to verify correctness and optimality.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.