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 account

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

🏆 All Time Leaderboard

Contest runs January 1, 1970 - December 31, 9999. Complete challenges to climb the leaderboard!

Points are calculated for challenges completed during the contest period.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In