Count Days Without Meetings - Problem

You are given a positive integer days representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array meetings of size n where meetings[i] = [start_i, end_i] represents the starting and ending days of meeting i (inclusive).

Return the count of days when the employee is available for work but no meetings are scheduled.

Note: The meetings may overlap.

Input & Output

Example 1 — Basic Case with Overlapping
$ Input: days = 10, meetings = [[5,7],[1,3],[9,10]]
Output: 2
💡 Note: Meeting days are: 1,2,3 (first meeting), 5,6,7 (second meeting), 9,10 (third meeting). Free days are: 4,8. Total free days = 2.
Example 2 — No Meetings
$ Input: days = 4, meetings = []
Output: 4
💡 Note: No meetings scheduled, so all 4 days (1,2,3,4) are free for work.
Example 3 — All Days Busy
$ Input: days = 3, meetings = [[2,4]]
Output: 1
💡 Note: Meeting covers days 2,3. Only day 1 is free (day 4 is beyond the available days). Free days = 1.

Constraints

  • 1 ≤ days ≤ 109
  • 0 ≤ meetings.length ≤ 1000
  • 1 ≤ starti ≤ endi ≤ days

Visualization

Tap to expand
Count Days Without Meetings: Find Free Days in ScheduleInput: days = 10, meetings = [[5,7], [1,3], [9,10]]Available Days (1 to 10):12345678910After marking meeting days as busy:12345678910■ Meeting Days: [1,3], [5,7], [9,10]■ Free Days: 4, 8Output: 2 free days(Days 4 and 8 are available)
Understanding the Visualization
1
Input
days=10, meetings=[[5,7],[1,3],[9,10]]
2
Process
Identify busy days from meetings
3
Output
Count remaining free days
Key Takeaway
🎯 Key Insight: Convert overlapping intervals into non-overlapping ones, then count the gaps between them
Asked in
Google 23 Microsoft 18 Amazon 15
23.4K Views
Medium Frequency
~25 min Avg. Time
847 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen