← Visualizers
Opposite-Ends Two Pointers LeetCode 18

4Sum / visualized

Same trick as 3Sum, nested one level deeper: fix i, fix j, then converge left / right on what's left. Every fixed pointer gets its own duplicate guard — four in total.

Execution

idle
Press Run to begin.
0 / 0
Speed

Java · running line

fixed i fixed j left right quad found dup skip
O(n³) time · O(1) extra (excluding output)  ·  same recipe generalizes to any k — see the kSum visualizer.