Skip to content
QuizMaker logoQuizMaker
Activity
DSA Interview Patterns Roadmap

No lessons available

CONTENTS

Intervals: Merge, Meeting Rooms and Calendar Booking

Choose sorting, heaps, sweep line, or ordered maps for interval conflict and range problems.

DSA Interview Patterns Roadmap
Intervals and Ordered Map
dsa
coding interview
+5
May 29, 2026
21
A

Learning Outcome

Choose sorting, heaps, sweep line, or ordered maps for interval conflict and range problems.

Pattern Recognition

ItemDetail
Core signalThe input is start/end ranges and the question asks merge, overlap, rooms, or dynamic booking.
Use whenIntervals can be compared by start/end or queried online by neighboring ranges.
Avoid whenThe required invariant is not monotonic or the input constraints point to a simpler direct scan.

Intuition

Most interval decisions are local after sorting: only the previous merged end or earliest active end matters.

Exact Practice Question Names

  • Merge Intervals
  • Meeting Rooms
  • Meeting Rooms II
  • Meeting Rooms III
  • My Calendar I
  • Range Module

Interview Approach

  1. Sort by start for merge and conflict checks.
  2. Use a min-heap of end times for room counts.
  3. Use sweep line for peak overlap.
  4. Use ordered map/set lower_bound for online calendar/range modules.

Pseudocode

sort intervals by start
activeEnds = minHeap
for interval in intervals:
  while activeEnds.min <= interval.start: pop
  push interval.end
  answer = max(answer, heap size)

Sample Dry Run

For meetings [0,30],[5,10],[15,20], the heap reaches size 2 at time 5, then reuses one room before [15,20].

Edge Cases

  • end == start may not overlap
  • Unsorted input
  • Nested intervals
  • Online operations where sorting all input is impossible

Common Mistakes

  • Sorting by end for merge intervals
  • Treating touching intervals as overlap in meeting rooms
  • Not checking previous and next neighbor in calendar booking

Complexity

ItemDetail
Expected timeO(n log n) for sorting/heap variants; O(log n) per online ordered-map operation.
Expected spaceO(n).

Java, C++ and Python Notes

  • Java: prefer explicit classes and clear helper methods over clever one-liners.
  • C++: use vector, unordered_map, set, priority_queue, and long long when sums can grow.
  • Python: keep state readable with dict, set, deque, heapq, and lru_cache where appropriate.

Quick Revision Checklist

  • Name the pattern before coding.
  • State the invariant or DP state in one sentence.
  • Dry-run the smallest non-trivial example.
  • Close with time and space complexity.

Share this article

Share on TwitterShare on LinkedInShare on FacebookShare on WhatsAppShare on Email

Test your knowledge

Take a quick quiz based on this chapter.

mediumDSA Interview Patterns
Quiz: Intervals: Merge, Meeting Rooms and Calendar Booking
6 questions10 min

0 comments

Please login to comment.
No comments yet.
Lesson 1 of 2 in Intervals and Ordered Map
Next in Intervals and Ordered Map
Ordered Map / Range Problems
Back to DSA Interview Patterns Roadmap
Back to moduleCategories