Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Sort intervals by start time. Initialize the result with the first interval. For each subsequent interval, check if it overlaps with the last merged interval (prev.end >= curr.start). If so, extend the previous interval. Otherwise, add the current interval as new.
Sorting by start time ensures we only need to compare each interval with the last merged one. If the current interval starts before or at the previous end, they overlap. Taking the max of ends handles contained intervals correctly.
Updated Feb 2026