Sorting•Pattern: Sorting + Greedy•Medium

Merge intervals

Problem Intuition & Objective

Merge all overlapping intervals from a list.

Time ComplexityO(n log n)
Optimal
Space ComplexityO(n)
Memory Bounds
Optimal Algorithmic Approach

Sort + linear scan.

Core Invariants & Edge Cases

  • Sort intervals by start time
  • Compare each interval's start with the last merged interval's end
  • If overlapping, extend the end; otherwise push a new interval
Previous ProblemFind peak element in unsorted arrayNext Problem Sort colors (Dutch National Flag)

System Design & Architecture Roadmap

Coding interviews are only 50% of the bar. Master High-Level Design, distributed systems, and Object-Oriented LLD.