← Visualizers
Two Pointers · two-sequence advance LeetCode 986

Interval List Intersections / visualized

Same machine as the string version — one pointer per sequence, both starting at the left, both only moving right — except the cells are intervals on a shared number line. The overlap of A[i] and B[j] is always [max(startA, startB), min(endA, endB)], and it is a real interval only when that lo ≤ hi. Then comes the only decision in the problem: retire whichever interval ends first. It is finished — every remaining interval in the other list starts at or after the one you just compared, so a bar that has already ended can never meet any of them.

Execution

idle
Aptr i
Bptr j
result
Press Run to begin.
0 / 0
Speed

Java · running line

A[i] — live interval B[j] — live interval recorded intersection retired / empty overlap
O(m + n) time · O(1) extra space beyond the output  ·  each step retires exactly one interval, so the loop runs at most m + n times. The rule to remember: lo = max(starts), hi = min(ends), then advance the pointer whose interval ends first.