Question bankPricingSign in

Merge Overlapping Intervals

IntervalsEasy1:00

Given a collection of intervals where each interval is a pair [start, end], merge all overlapping intervals and return the result.

For example, given [[1,3],[2,6],[8,10],[15,18]], the merged result is [[1,6],[8,10],[15,18]] because [1,3] and [2,6] overlap.

Explain your approach step by step and analyze the time and space complexity.

How to approach it

  • Hint 1

    What happens if you sort the intervals by their start time first?

  • Hint 2

    After sorting, two consecutive intervals overlap if the current interval's start is less than or equal to the previous interval's end.

  • Hint 3

    When intervals overlap, merge them by extending the end to the maximum of both ends.

Ready to answer it out loud?

Record your answer in 1:00 and Preptile scores it 1–10 with specifics — what landed, what you skipped, and what to say next time.

Practising needs an invite code. Join the waitlist and we’ll send you one.