As reported: Walmart (Sam's Club) SDE III onsite, round 1 DSA (Bangalore, Apr 2026): merge intervals; follow-up — the intervals arrive as a stream, how do you keep the merged / overlapping intervals correct?
Given an array of intervals where intervals[i] = [start, end], merge all overlapping intervals and return the non-overlapping intervals that cover exactly the same ranges.
This is LeetCode 56 — Merge Intervals.
Example
[[1,3],[2,6],[8,10],[15,18]] -> [[1,6],[8,10],[15,18]]
[[1,4],[4,5]] -> [[1,5]] (touching intervals merge)
Follow-ups
- The intervals arrive one at a time as a stream. Keep the merged intervals correct after every arrival.
Constraints: 1 ≤ intervals.length ≤ 10^4; 0 ≤ start ≤ end ≤ 10^4.
Code runner format: one line with intervals as a JSON array. Implement merge(intervals); any order of the result is accepted (the harness sorts it).