Coding questions · NVIDIA
Merge Overlapping Time Intervals
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.
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:
def merge_intervals(intervals: list[list[int]]) -> list[list[int]]:
pass
Examples:
Input: [[1, 3], [2, 6], [8, 10], [10, 12]]
Output: [[1, 6], [8, 12]]
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
Merge Overlapping Time Intervals
Merge overlapping or touching closed intervals and return the minimal sorted interval list.