See all coding puzzles and patterns here.


Algorithm Description

A two pointer approach to certain coding problems involves keeping 2 pointers referencing elements in a data structure and then changing where those 2 pointers point in order to find a solution to the problem.


Performance Characteristics

The overall algorithm results in a $O(n)$ runtime since the two pointers might have to be moved over all $n$ references in the data structure. The internals of the algorithm can result in a higher overall runtime.

For example, if at every iteration, the entirety of the data structure is referenced, the overall runtime would be $O(n^2)$.

Because only 2 additional pointers to existing data in memory are being stored, the memory overhead for this technique is $O(1)$. However, again, the internals can result in a higher space complexity.


Puzzles

Puzzle Difficulty External Link
Valid Palindrome III Hard Leetcode 1216 (Premium)