← Visualizers
Advanced Two Pointers LeetCode 16

3Sum Closest / visualized

Same skeleton as 3Sum — sort, fix i, converge left/right — but instead of collecting exact matches, track whichever sum has landed closest to the target so far. An exact match is just the closest possible sum, so it short-circuits immediately.

Execution

idle
Press Run to begin.
0 / 0
Speed

Java · running line

fixed i left right closest so far
O(n²) time · O(log n)–O(n) sort space  ·  no duplicate-skipping needed here — closeness to target doesn't care which duplicate triplet produced it.