AlgoBazaAlgoBaza
Back to algorithms

Two Pointers

An algorithmic technique using two pointers moving through an array to solve a problem.

Sredni
O(n)O(1)OIJOI
Applications
  • •Finding a pair with a given sum
  • •Removing duplicates
  • •Reversing an array
  • •Three sum problem
Complexity

Time

O(n)

Memory

O(1)

How does Two Pointers work?

An algorithmic technique using two pointers moving through an array to solve a problem.

Analogy

Like two people walking toward each other in a long hallway - one from the beginning, one from the end - they meet somewhere in the middle.