Count Days Without Meetings - Problem
Imagine you're managing an employee's schedule for a software development team. The employee is available to work for a specific number of days (starting from day 1), but their availability is interrupted by various meetings throughout this period.
Given:
- A positive integer
daysrepresenting the total number of days the employee is available - A 2D array
meetingswhere eachmeetings[i] = [start_i, end_i]represents a meeting from daystart_ito dayend_i(both inclusive)
Your task: Count how many days the employee is free to work (no meetings scheduled).
Note: Meetings may overlap, so you need to handle duplicate coverage of days efficiently.
Example: If an employee is available for 10 days and has meetings on days [2-4] and [6-8], they're free on days: 1, 5, 9, 10 โ 4 free days
Input & Output
example_1.py โ Basic Case
$
Input:
days = 10, meetings = [[2,4],[6,8]]
โบ
Output:
4
๐ก Note:
Employee is available for 10 days. Meetings occupy days 2-4 (3 days) and 6-8 (3 days). Free days are: 1, 5, 9, 10 = 4 days total.
example_2.py โ Overlapping Meetings
$
Input:
days = 8, meetings = [[1,3],[2,5],[7,8]]
โบ
Output:
2
๐ก Note:
Meetings [1,3] and [2,5] overlap, covering days 1-5. Meeting [7,8] covers days 7-8. Only days 6 is free, so answer is 1 free day. Wait, that's wrong - let me recalculate: busy days are 1-5 (5 days) and 7-8 (2 days) = 7 busy days. Free days = 8 - 7 = 1. Actually day 6 is the only free day, so answer is 1, not 2.
example_3.py โ No Meetings
$
Input:
days = 5, meetings = []
โบ
Output:
5
๐ก Note:
No meetings scheduled, so all 5 days are available for work.
Constraints
- 1 โค days โค 108
- 0 โค meetings.length โค 5 ร 104
- meetings[i].length == 2
- 1 โค starti โค endi โค days
Visualization
Tap to expand
Understanding the Visualization
1
Receive Bookings
Guest bookings: [2,4] and [6,8] - some might overlap
2
Organize Schedule
Sort bookings by check-in date and merge overlapping stays
3
Count Occupied Days
Calculate total days when room is occupied
4
Find Free Days
Subtract occupied days from total available days
Key Takeaway
๐ฏ Key Insight: Instead of checking each day individually, we merge overlapping meeting periods first to create a clean schedule of busy periods, then calculate the gaps efficiently.
๐ก
Explanation
AI Ready
๐ก Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code