Two Pointers Interview Questions 2026

Two pointers is a meta-technique that appears across arrays, strings, and linked lists. Recognizing which variant applies is the key skill.

Opposite-Direction Pointers

Start one pointer at each end of a sorted structure, move toward the center based on the comparison result. Use case: two-sum in sorted array, check if string is palindrome, trap rain water, container with most water.

Decision rule: if the sum is too small, move the left pointer right (increase). If too large, move the right pointer left (decrease). The key insight: moving the pointer with the smaller value cannot make things worse.

Same-Direction Pointers

Both pointers start at the beginning and advance at different rates. Use case: remove duplicates in sorted array, move zeros to end, merge sorted arrays in place, remove element in-place.

Pattern: slow pointer is the write position (or the boundary of valid elements). Fast pointer scans ahead. When fast finds a valid element, write it to slow and advance slow.

Partition Problems

Partition an array around a pivot (3-way partition for Dutch National Flag / sort colors). Three pointers: lo, mid, hi. Elements in [0,lo) are less than pivot, [lo,mid) equal, [hi+1,n) greater.

Interviewers often ask: sort an array of 0s, 1s, and 2s in one pass without extra space. This is Dutch National Flag. Walk through the invariant carefully; it is easy to lose track of which region mid belongs to.

String Two Pointers

Valid palindrome with characters to skip: advance each pointer past non-alphanumeric characters, then compare. Two-pointer squeeze for palindrome checking handles the constraint cleanly without pre-processing.

Minimum window substring is a two-pointer (sliding window) problem on strings. Expand right until all required characters are covered; shrink left to minimize the window. Use a frequency map and a count of satisfied characters.

Browse Real Two Pointer Questions

Actual two-pointer problems from FAANG and top tech companies.

Browse Two Pointer Questions