Practice The Number of the Smallest Unoccupied Chair
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
The Number of the Smallest Unoccupied Chair
Problem Statement
There is a party where n friends numbered from 0 to n - 1 are attending. There is an infinite number of chairs in this party that are numbered from 0 to infinity. When a friend arrives at the party, they sit on the unoccupied chair with the smallest number. When a friend leaves the party, their chair becomes unoccupied at the moment they leave. If another friend arrives at that same moment, they can sit in that chair. You are given a 0-indexed 2D integer array times where times[i] = [arrivali, leavingi], indicating the arrival and leaving times of the ith friend respectively, and an integer targetFriend. All arrival times are distinct. Return the chair number that the friend numbered targetFriend will sit on.
Source: The Number of the Smallest Unoccupied Chair on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
times = [[1,4],[2,3],[4,6]], targetFriend = 1
1
# Example 2
times = [[3,10],[1,5],[2,6]], targetFriend = 0
2
Constraints
Related LeetCode Problems
Practice more problems similar to The Number of the Smallest Unoccupied Chair.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.