LeetCode Patterns · Dual-probe reasoning

Two Pointers Visualizer

Watch every pointer movement become a proof: compare, eliminate, preserve the invariant, and narrow the search without losing an answer.

Input studio

Two Sum II

Use sorted order to eliminate impossible pairs.

MediumConverging probes
Sorted input required

Probe console

Ready to launch

Choose a problem, configure its input, and launch the probes.

Unified array track

Pointer Rail

StateReady
Values4
2
0
7
1
11
2
15
3
ComparedPointerCommittedBest pair

Live decision inspector

Why does a probe move?

Ready

What will each probe prove?

waiting for execution

Next action

Launch the Pointer Rail

Use sorted order to eliminate impossible pairs.

Invariant

Every possible answer remains inside the active interval.

Safely eliminated

Nothing yet

Execution trace

Code in motion

def two_sum(numbers, target):
left, right = 0, len(numbers) - 1
while left < right:
total = numbers[left] + numbers[right]
if total == target: return [left, right]
if total < target: left += 1
else: right -= 1
return []

Local mastery

Your pattern record

Pair Sum0 tries0%
Palindrome0 tries0%
Deduplicate0 tries0%
Max Area0 tries0%

Completion and best prediction accuracy stay in this browser. No account is required.

Recognize the pattern

When should you use two pointers?

Look for sorted arrays, mirrored comparisons, in-place transformations, or pair optimization. The key is monotonic information: after each comparison, one pointer can move while safely eliminating several candidates.

Ask yourself: “What does moving this pointer prove can never be an answer?” If that proof is clear, two pointers may reduce a quadratic search to one pass.