Merge Overlapping Time Intervals
Company: NVIDIA
Role: Data Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
You are given a list of closed time intervals. Each interval is represented as `[start, end]`, where `start <= end`. Write a function that returns the smallest list of intervals covering the same ranges after merging any intervals that overlap or touch.
Two intervals touch if the end of one interval is equal to the start of the next interval.
Implement:
```python
def merge_intervals(intervals: list[list[int]]) -> list[list[int]]:
pass
```
Examples:
```text
Input: [[1, 3], [2, 6], [8, 10], [10, 12]]
Output: [[1, 6], [8, 12]]
```
```text
Input: [[5, 7], [1, 2], [2, 4], [9, 9]]
Output: [[1, 4], [5, 7], [9, 9]]
```
Requirements:
- Return intervals sorted by start time.
- Do not mutate the caller's input.
- Handle an empty input list.
- Handle duplicate intervals, single-point intervals, negative times, and unsorted input.
Constraints:
- `0 <= len(intervals) <= 100000`
- Each interval has exactly two integer values.
- `-10^9 <= start <= end <= 10^9`
Quick Answer: Practice a NVIDIA coding interview problem focused on merge overlapping time intervals. The prompt emphasizes edge cases, clean implementation, and verifiable test behavior without revealing the solution.
Merge overlapping or touching closed intervals and return the minimal sorted interval list.
Examples
Input: ([[1,3],[2,6],[8,10],[10,12]],)
Expected Output: [[1,6],[8,12]]
Explanation: Overlapping and touching intervals are merged.
Input: ([],)
Expected Output: []
Explanation: Empty input.