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 INPUT Days Timeline (1-10) 1 2 3 4 5 6 7 8 9 10 Meetings Array: Meeting 1: [5, 7] Meeting 2: [1, 3] Meeting 3: [9, 10] Input Values: days = 10 meetings = [[5,7], [1,3], [9,10]] ALGORITHM STEPS 1 Create Boolean Array marked[1..10] = false 2 Mark Meeting Days For each [start, end]: mark days start..end = true 3 Process All Meetings [1,3]: mark 1,2,3 [5,7]: mark 5,6,7 [9,10]: mark 9,10 T T T F T T T F T T 4 Count False Values Days 4 and 8 are false Count = 2 4 8 Free Days! FINAL RESULT Final Day Status 1 MTG 2 MTG 3 MTG 4 FREE 5 MTG 6 MTG 7 MTG 8 FREE 9 MTG 10 MTG Meeting [1,3] Meeting [5,7] Meeting [9,10] Free Day Output 2 OK - 2 days without meetings (Days 4 and 8 are free) Key Insight: Boolean Array Marking is efficient for tracking occupied days. Create an array of size (days+1), mark each day within meeting ranges as true, then count remaining false values. Time: O(n * m) where n = meetings, m = avg meeting length. Space: O(days) for the boolean array. TutorialsPoint - Count Days Without Meetings | Boolean Array Marking Approach
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