Ctrl K

Fewest Rooms for the Bookings

Medium
A coworking space takes meeting room bookings: bookings[i] = [start, end] means a team holds a room from day start through day end inclusive. Two bookings cannot share a room if they have at least one day in common; for example, [1, 5] and [5, 8] clash. Return the smallest number of rooms that can hold all the bookings.
Example 1
bookings=[[2, 4], [5, 7], [4, 6], [8, 9]] → 2

Bookings [2, 4] and [4, 6] share day 4, so two rooms are needed: for example [2, 4] and [5, 7] in one room, [4, 6] and [8, 9] in the other.

Example 2
bookings=[[1, 10], [3, 3], [3, 5]] → 3

All three bookings cover day 3, so three rooms are needed.

Example 3
bookings=[[6, 6]] → 1
Constraints
  • 1 ≤ len(bookings) ≤ 10⁵
  • 1 ≤ start ≤ end ≤ 10⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsStudios for Recording Sessions MediumMost Spare Ranges MediumFlowerbed Beauty on a Budget HardFix the Middle of the Line MediumStick Triples That Form a Triangle Medium
loading Python…
Input
bookings=[[2, 4], [5, 7], [4, 6], [8, 9]]
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 97 tests on the server, hidden ones included.