On this page
Merge Intervals
Solving Merge Intervals using Sorting.
Problem
Merge overlapping intervals.
Pattern
This problem demonstrates the Sorting pattern.
Approach
Sort by start, merge if overlap.
Solution
// Solution for Merge Intervals
// Pattern: Sorting
// O(n log n) time
Complexity
O(n log n) time
Best Practices
- Identify the pattern before coding — pattern recognition saves time
- Handle edge cases: empty input, single element, duplicates
- Use descriptive variable names even in timed interviews
- Test with the provided examples plus one custom case