Skip to content
DSA Visualizerpreview

Two sum (sorted)

Find two values that add up to a target, walking in from both ends.

O(n) time · O(1) space

Values1, 3, 4, 6, 8, 11, 14, 17sum 19

Find two values in 1, 3, 4, 6, 8, 11, 14, 17 that add up to 19. Start l at the left end and r at the right.

Array of 8 values: 1, 3, 4, 6, 8, 11, 14, 17. Active index 0 (1) and index 7 (17). Pointers l at index 0 and r at index 7.
  • compare
  • swap or write
  • settled

1 / 15

Speed

Space play · ← → step · Home End jump · drag the strip to scrub