← All mock interviewsHints used: 0
Merge Intervals Mock Interview
- ✓Problem→
- 2Clarifying Questions→
- 3Constraints→
- 4Brute Force→
- 5Complexity Analysis→
- 6Pattern Recognition→
- 7Optimized Solution→
- 8Implementation→
- 9Testing→
- 10Follow-Up→
- 11Evaluation
Problem
Given an array of intervals where intervals[i] = [start_i, end_i], merge all overlapping intervals and return an array of the non-overlapping intervals that cover all the intervals in the input. Two intervals that merely touch (one ends where the other starts) are considered overlapping.
Constraints
- 1 ≤ n ≤ 10^4
- 0 ≤ start_i ≤ end_i ≤ 10^4
- input is not necessarily sorted
Example
in: intervals = [[1,3],[2,6],[8,10],[15,18]]
out: [[1,6],[8,10],[15,18]]
Clarify
Before choosing anything: what would you ask the interviewer? What assumptions are you making? (Duplicates? Empty input? Value ranges? What to return when there is no answer?)