The Mirror Formula

Union takes the widest span: [min(starts), max(ends)].

What if you want the narrowest overlap — just the region where both intervals are active?

Flip every min to max and every max to min. That is the entire insight.

[max(starts), min(ends)] — valid when lo <= hi.

Merge and intersection are duals. Once you see it, you never confuse them again.

Intersect Two Lists

Two sorted interval lists. Find every region where BOTH have coverage.

Start by checking pairs the naive way — then watch the two-pointer path emerge.

Naive phase. Manually check pairs of intervals to find intersections.

Find all intersections between List A and List B. Tap an interval from A, then one from B to check each pair.

List AList B
[0,2]
[5,10]
[13,23]
[24,25]
[1,5]
[8,12]
[15,24]
[25,26]
0
2
4
6
8
10
12
14
16
18
20
22
24
26
Pairs checked: 0 / 16Found: 0

Handling Gaps

Not every interval in one list has a partner in the other. When there is no intersection, the pointer advancement rule still applies.

Naive phase. Manually check pairs of intervals to find intersections.

Find all intersections between List A and List B. Tap an interval from A, then one from B to check each pair.

List AList B
[0,3]
[7,10]
[2,5]
[6,8]
[11,15]
0
2
4
6
8
10
12
14
16
Pairs checked: 0 / 6Found: 0