Tap here to switch tabs
Problem
Submissions

Problem: The Number of the Smallest Unoccupied Chair

med
30 min
Understand how to apply heap data structures to solve problems involving dynamic seat allocation. This lesson helps you determine the smallest available chair number for a specific friend based on their arrival and departure times, practicing real-time resource management techniques.

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

med
30 min
Understand how to apply heap data structures to solve problems involving dynamic seat allocation. This lesson helps you determine the smallest available chair number for a specific friend based on their arrival and departure times, practicing real-time resource management techniques.

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.