Two Pointers

Uses two indices to scan or compare elements efficiently.

2
7
11
15
L
R
Initialize pointers at both ends.

Where It's Used

  • Problems involving sorted arrays.
  • Comparing elements from both ends.
  • Finding pairs or combinations that satisfy a condition.
  • Scanning arrays or strings with two moving indices.

Problems Using This Pattern

Two Sum II (Input Array Is Sorted)

Two Pointers

Container With Most Water

Two Pointers

Valid Palindrome

Two Pointers

Remove Duplicates from Sorted Array

Two Pointers

3Sum

Two Pointers