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!
How 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 July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.