Merge overlapping time intervals
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Technical Screen
## Problem
You are given a list of **closed** intervals `intervals`, where each interval is `[start, end]` and `start <= end`.
Merge all intervals that overlap and return the resulting list of merged intervals.
Two intervals `[a, b]` and `[c, d]` are considered overlapping if `c <= b` (i.e., touching at an endpoint also counts as overlapping).
## Input
- `intervals`: a list of `n` intervals, each represented as two integers `[start, end]`.
## Output
- A list of merged, non-overlapping intervals, sorted by increasing `start`.
## Constraints
- `0 <= n <= 1e5`
- `-1e9 <= start <= end <= 1e9`
## Example
Input: `[[1,3],[2,6],[8,10],[15,18]]`
Output: `[[1,6],[8,10],[15,18]]`
Quick Answer: This question evaluates a candidate's understanding of interval arithmetic, sorting and array manipulation, specifically the ability to merge overlapping ranges efficiently.
Merge overlapping closed time intervals and return sorted non-overlapping intervals.
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([[1,3],[2,6],[8,10],[15,18]],)
Expected Output: [[1, 6], [8, 10], [15, 18]]
Explanation: Overlapping intervals merge.
Input: ([[1,4],[4,5]],)
Expected Output: [[1, 5]]
Explanation: Touching closed intervals merge.
Hints
- Clarify edge cases before coding.
- Keep the return value deterministic.