All problems
1096MediumArraySorting

Days the Workshop Stays Free

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3169Count Days Without Meetings

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A workshop takes bookings over days days numbered 1 through days. bookings[i] = [first, last] reserves the workshop for every day from first to last, both ends included. Bookings may overlap, sit inside one another or arrive in any order.

Return how many of the days days carry no booking at all.

Examples

Example 1

Input
days = 12, bookings = [[5, 7], [1, 3], [9, 10]]
Output
4

Days 1 to 3, 5 to 7 and 9 to 10 are reserved. Day 4, day 8, day 11 and day 12 are left.

Example 2

Input
days = 20, bookings = [[5, 10], [6, 8], [7, 7]]
Output
14

The second and third bookings sit wholly inside the first, so only days 5 to 10 are reserved and the other fourteen days stay free.

Example 3

Input
days = 1, bookings = [[1, 1]]
Output
0

The workshop's single day is booked.

Constraints

  • 1 <= days <= 10^9
  • 1 <= bookings.length <= 10^5
  • bookings[i].length == 2
  • 1 <= bookings[i][0] <= days
  • 1 <= bookings[i][1] <= days
  • bookings[i][0] <= bookings[i][1]

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def count_days(days: int, bookings: list[list[int]]) -> int:
Java
public int countDays(int days, int[][] bookings)
September 7
Apply