Assign bookings to minimum tennis courts
Company: Atlassian
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
You are given a list of tennis court bookings. Each booking has a **start** time and an **end** time.
## Task
Return an assignment plan that:
1. Assigns **each booking** to a specific court (e.g., court IDs `1..k`).
2. Ensures **no court has overlapping bookings**.
3. Uses the **minimum number of courts** (assume unlimited courts are available).
You may return:
- The **minimum number of courts** needed, and
- An **array of court IDs** aligned with the input bookings (i.e., `assignment[i]` is the court used by booking `i`).
## Follow-up: Maintenance buffer
After a booking ends, the court is unavailable for a fixed **maintenance time** `M` (e.g., minutes). That means a booking `[s2, e2]` can reuse the same court after booking `[s1, e1]` only if:
- `s2 >= e1 + M`
Update your approach to support this requirement.
## Notes / Assumptions
- Time can be treated as integers.
- You should aim for an efficient solution (e.g., for large `n`).
Quick Answer: This question evaluates interval scheduling and resource-allocation competencies, testing algorithmic and data-structure knowledge for handling time-interval conflicts and producing a minimal concurrent-resource assignment.
Assign each booking to the smallest available court id with optional maintenance buffer. Return court count and assignment aligned to input.
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([[0,30],[5,10],[15,20]], 0)
Expected Output: {'courts': 2, 'assignment': [1, 2, 2]}
Explanation: Two courts.
Input: ([[0,10],[10,20]], 0)
Expected Output: {'courts': 1, 'assignment': [1, 1]}
Explanation: Reuse without buffer.
Input: ([[0,10],[10,20]], 5)
Expected Output: {'courts': 2, 'assignment': [1, 2]}
Explanation: Buffer requires another court.
Hints
- Use deterministic tie-breaking for prompts with multiple valid outputs.
- For design-style APIs, simulate operations with explicit inputs.