← 返回 snowflake 的题目列表Merge Intervals
类型:qbank
Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.
Merge Intervals
Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.
SWE
interval
sorting
array
medium
Frequency
Single report
Last asked
2026-01-20
Stage
phone-screen · onsite-coding
Merge Intervals
Problem Explanation
You are given an array called intervals. Each item in this list represents a range with a starting point and an ending point, written as [start, end].
Your task is to combine any intervals that overlap. You need to return a new list of intervals where no two ranges touch or cross each other. This new list must still cover all the ground that the original list did.
You are allowed to return the answer in any order.
Key Concept: Intervals are considered "non-overlapping" only if they do not touch at all.
Separate: [1, 2] and [3, 4] do not overlap.
Overlapping: [1, 2] and [2, 3] are considered overlapping because they touch at the number 2.
Illustrative Examples
Case 1:
Input: intervals = [[1,3],[1,5],[6,7]]
Output: [[1,5],[6,7]]
Case 2:
Input: intervals = [[1,2],[2,3]]
Output: [[1,3]]
Input Limits
1 <= intervals.length <= 1000
intervals[i].length == 2
0 <= start <= end <= 1000