Tap here to switch tabs
Problem
Submissions

Problem: The Number of the Smallest Unoccupied Chair

The Number of the Smallest Unoccupied Chair assigns each arriving friend the lowest available chair, with departures freeing chairs immediately. Given arrival and leaving times, return the chair used by a target friend.

Statement

At a party, nn friends, numbered from 00 to n−1n - 1, arrive and leave at different times. There are infinitely many chairs, numbered 00 onwards. Each arriving friend sits on the smallest available chair at that moment.

For example, if chairs 00, 11, and 55 are occupied when a friend arrives, they will sit on chair number 22.

When a friend leaves, their chair becomes immediately available. If another friend arrives simultaneously, they can take that chair.

You are given a 00-indexed 2D2D list times, where times[i] =[arrivali,leavingi]= [ arrival_i, leaving_i] represents the arrival and departure times of the ithi_{th} friend. All arrival times are unique.

Given an integer target_friend, return the chair number that target_friend will sit on.

Constraints:

  • n==n == times.length

  • times[i].length ==2== 2

  • 1≤1\leq arrivali < leavingi ≤105\leq 10^5

  • 0≤0 \leq target_friend ≤n−1\leq n - 1

  • Each arrivali time is unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: The Number of the Smallest Unoccupied Chair

The Number of the Smallest Unoccupied Chair assigns each arriving friend the lowest available chair, with departures freeing chairs immediately. Given arrival and leaving times, return the chair used by a target friend.

Statement

At a party, nn friends, numbered from 00 to n−1n - 1, arrive and leave at different times. There are infinitely many chairs, numbered 00 onwards. Each arriving friend sits on the smallest available chair at that moment.

For example, if chairs 00, 11, and 55 are occupied when a friend arrives, they will sit on chair number 22.

When a friend leaves, their chair becomes immediately available. If another friend arrives simultaneously, they can take that chair.

You are given a 00-indexed 2D2D list times, where times[i] =[arrivali,leavingi]= [ arrival_i, leaving_i] represents the arrival and departure times of the ithi_{th} friend. All arrival times are unique.

Given an integer target_friend, return the chair number that target_friend will sit on.

Constraints:

  • n==n == times.length

  • times[i].length ==2== 2

  • 1≤1\leq arrivali < leavingi ≤105\leq 10^5

  • 0≤0 \leq target_friend ≤n−1\leq n - 1

  • Each arrivali time is unique.