← 返回 bytedance 的题目列表Merge Intervals
类型:qbank
The canonical LeetCode 56 prompt: merge every overlapping interval and return the non-overlapping intervals that cover the same ranges.
Requirements
Given an array of intervals where each interval is [start, end], merge all overlapping intervals.
Return the resulting non-overlapping intervals covering the same ranges.
Preserve closed-interval overlap semantics: intervals that touch at an endpoint merge.
Examples
Input: intervals = [[1,3],[2,6],[8,10],[15,18]]
Output: [[1,6],[8,10],[15,18]]
Input: intervals = [[1,4],[4,5]]
Output: [[1,5]]
Notes
The prompt was identified as LC 56 without an additional twist.
The screen began with a resume discussion and technical-challenge follow-ups, followed by roughly 25 minutes for coding.
A newer screen used this as the first of two coding tasks. Finishing it quickly led directly to a transactional database-update exercise, so budget time for a possible second prompt even when the first task is familiar.
Preparation
Implement the sort-and-scan solution from a blank editor and explain the overlap invariant before writing code.
Drill touching endpoints, nested intervals, a single interval, and input presented in reverse order.
State the time and space costs, including whether the output array is counted as auxiliary space.