Given a list of intervals where each interval is represented as a list of two integers [start, end], merge all overlapping intervals and return the merged result. Intervals overlap if they share at least one common point. Return the merged intervals sorted by start time.
Examples:
Input: intervals = [[1,3], [2,6], [8,10], [15,18]]
Output: [[1,6], [8,10], [15,18]]
Explanation: Intervals [1,3] and [2,6] overlap, so they merge into [1,6]
Input: intervals = [[1,4], [4,5]]
Output: [[1,5]]
Explanation: Intervals touch at point 4, so they merge into a single interval
Input: intervals = [[1,4], [2,3]]
Output: [[1,4]]
Explanation: [2,3] is completely contained within [1,4]
Apex Code Editor
Welcome to Lightning Challenge!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay Mar 2026
Contest runs March 3 - 31. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.