Tennis Court Scheduling
Updated
Problem statement
Schedule every reservation on a tennis court. Each row [start, end] of reservations is one booking, identified by its original array index.
For this exercise, courts have identical availability, and a booking occupies the half-open time interval [start, end). Two bookings may share a court when the first ends exactly when the second starts. Every booking must be assigned without delaying, shortening, or rejecting it.
Deterministic allocation
- Process reservations in increasing start-time order. If start times are equal, process the smaller original array index first.
- Before assigning a reservation, release every court whose current booking ends at or before its start time.
- Assign the smallest ID among the free courts. If no court is free, create the next court ID. Court IDs start at
0and increase consecutively.
Return one court ID for each reservation, in the original input order. This allocation uses the minimum number of courts needed to honor all bookings. For empty input, return an empty array.
Function
assignTennisCourts(reservations: int[][]) → int[]Examples
Example 1
reservations = [[5,8],[1,4],[2,6],[4,5]]return = [0,0,1,0]Process input indices 1,2,3,0. They receive courts 0,1,0,0. A booking ending at time 4 releases court 0 for the booking starting at 4; return the assignments in original input order.
Example 2
reservations = [[0,10],[1,3],[2,4],[10,12]]return = [0,1,2,0]The first three bookings overlap and need courts 0,1,2. At time 10 all are free, so the last booking uses the smallest ID, court 0.
Example 3
reservations = []return = []There are no reservations and no court assignments.
Constraints
0 <= reservations.length <= 100000.- Every row contains exactly two integers.
0 <= start < end <= 10^9.- Reservations may be unsorted, overlap, or have identical intervals.
- Target
O(n log n)time andO(n)space, wherenis the reservation count.
More Atlassian Phone Screen questions
- Merge Overlapping IntervalsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
- Longest Consistent Activity StreakPHONE SCREEN · Seen Sep 2026
- Music Player Operation SequencePHONE SCREEN · Seen Sep 2026
- Underline Shortest Unique SubstringsPHONE SCREEN · Seen Aug 2026
- Can a Dictionary Word Be Formed from Note Letters?PHONE SCREEN · Seen Feb 2026
- Word Path Moving Only Right or DownPHONE SCREEN · Seen Feb 2026
- Ordered Badge Entry and Exit ViolationsPHONE SCREEN · Seen Aug 2025
- Two Sum with an Ordered Index PairPHONE SCREEN · Seen Aug 2025
- Can You Finish the Teleporter Board?PHONE SCREEN · Seen Jul 2025
Similar questions at other companies
- Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
- Select K Paired Indices for Maximum ScoreAmazon · ONSITE INTERVIEW
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
- Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
- Movie Schedule for Maximum EnjoymentC3.ai · ONSITE INTERVIEWC3.ai interview questions
- Schedule Unit-Time Jobs for the Most ProfitScale AI · PHONE SCREENScale AI interview questions
- Minimum Meeting RoomsSentry · PHONE SCREENSentry interview questions
- Allocate Customers to Preferred SitesYelp · ONSITE INTERVIEWYelp interview questions
- IPOTekion · PHONE SCREENTekion interview questions
- Minimum Refueling StopsUber · ONSITE INTERVIEWUber interview questions