Two Pointers Visualizer

Move left and right pointers through sorted pair-sum and container-area examples, then inspect each comparison and pointer decision.

Values
7
Left
0
Right
6
Sum
0

Array input

Step controls

Step 1 of 6: Sort values, then start left at 0 and right at 6.

Pointer diagram

Sort values, then start left at 0 and right at 6.

Pointer Best Found
1
0
L
2
1
4
2
6
3
8
4
11
5
15
6
R

Current state

Left value: 1

Right value: 15

Current sum: 0

Best: none yet

Pointer rule

The input is sorted first. If the sum is too small, move left rightward. If the sum is too large, move right leftward.

Target: 10

Sort values, then start left at 0 and right at 6.

What is a Two Pointers Visualizer?

A two pointers visualizer shows how two indexes move through an array while solving a problem. The pointers may start at opposite ends, move inward, or scan in the same direction depending on the pattern.

This tool includes sorted pair sum and container-with-most-water examples. It is useful for learning pointer movement, sorted-array logic, and interview-style array problems.

For the full cluster of related tools, browse the Data Structure Visualizers hub.

How to use this two pointers visualizer

  • Paste values such as [1, 2, 4, 6, 8, 11, 15].
  • Choose pair sum or container area mode.
  • Set a target sum when using pair sum mode.
  • Step through pointer movement from left and right.
  • Inspect the current pair, comparison, and best result.

Two pointers vs sliding window

Two pointers often starts with one pointer at the beginning and one at the end. Sliding window usually tracks a continuous subarray and adjusts boundaries based on a running condition.

Use this page with the Sliding Window Visualizer, Sorting Algorithm Visualizer, and Binary Search Tree Visualizer when comparing search patterns.

Frequently Asked Questions

Does pair sum mode sort the input?
Yes. Pair sum mode sorts the numeric input first, then uses the common left/right pointer approach.
What does container area mode show?
Container area mode shows the width, height, area, and best area while moving the pointer at the shorter line.
Can I paste duplicate numbers?
Yes. The visualizer preserves duplicates in both pair sum and area modes.
Why do the pointers move inward?
When the input is sorted or the problem has a monotonic rule, moving one pointer can eliminate many impossible pairs at once.

Related tools