2Brute2Best
🔥0

Count Days Without Meetings

Medium·LeetCode #3169 Pro OnlyPattern Transfer
LeetCode
01

Problem Statement

An employee works on days 1 to days. You get a list of meetings, where meetings[i] = [start, end] means a meeting runs on every day from start to end, including both. Meetings can overlap.

Return how many work days have no meeting at all.

Input

An integer days, and a list meetings of [start, end] pairs.

Output

One integer: the number of days in 1 … days that no meeting touches.

Example 1
Input: days = 10, meetings = [[5,7],[1,3],[9,10]]
Output: 2

Days 4 and 8 have no meeting.

Example 2
Input: days = 5, meetings = [[2,4],[1,3]]
Output: 1

The meetings together cover days 1 to 4. Only day 5 is free.

Example 3
Input: days = 6, meetings = [[1,6]]
Output: 0

One meeting fills every day.

Constraints
  • • 1 ≤ days ≤ 10^9
  • • 1 ≤ meetings.length ≤ 10^5
  • • meetings[i].length == 2
  • • 1 ≤ start ≤ end ≤ days
02

Pattern Recognition Clues

Recognising these key signals in the problem description immediately identifies the pattern:

“meetings may overlap”
→ Shared days must be counted once → merge overlapping ranges first.
“days up to 10^9”
→ A per-day array is impossible. Work with the ranges, not the days.
“start and end are both included”
→ A block holds `end − start + 1` days, not `end − start`.
03

Approach Complexity Ladder

Brute Force — one flag per dayO(D + N · L)O(D)

Mark every day of every meeting in a boolean array, then count unmarked days

Optimal — sort, merge on the fly, subtract covered daysO(N log N)O(1)

Merge the meetings into disjoint blocks and add each block's length once

Brute Force Intuition

Make an array busy of size days + 1. For each meeting, mark every day from start to end. Then count the days from 1 to days that are still unmarked.

Recognition rule for this sub-pattern:

Sort by start. If next.start ≤ current.end, they overlap — extend current.end. Otherwise start a new interval.
Remember this · Intervals
Trigger
Input is [start, end] pairs; overlap, merge, insert, meeting rooms, free time, minimum removals.
Think
After sorting, do I only ever need to compare against the most recent interval?
Key question
Sort by start or by end — which one makes the greedy choice obvious?
Brute2Best Pro Content

Unlock Complete Visual Walkthrough & Optimal C++

The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.

All 440 visual dry runs & algorithms
Interactive step-by-step playback with pointer & array state transitions
52 comprehensive LLD chapters
Interactive UML diagrams, real-world stories (Food Delivery, Trading, RPG), and practice solutions
40 C++ basics labs & hardware memory models
Vtables, byte layouts, assembly insights, and multi-threading race conditions
Production-ready C++23 source code
Modern idioms, clean contracts, time/space complexity derivations, and interview takeaways

First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.

Beyond The LeetCode Problem

How this concept connects to System Design & C++ Systems

Bridge DSA with production engineering

Top engineering interviews test whether you understand how algorithms like Intervals translate into production architectures and low-level memory mechanics.