Count Days Without Meetings
Real-world version: Days the Workshop Stays FreeThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def count_days(days: int, bookings: list[list[int]]) -> int:public int countDays(int days, int[][] bookings)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's