# Two Pointers

> Walking a list with two markers at once. Often one starts at each end.

**Field:** Software Development  
**Category:** Algorithms & Data Structures  
**Also known as:** Two-Pointer Technique, Two Pointer Method

## Think of it like

Think of it like two friends on a bench. They start at the ends and walk toward each other.

## Definition

The two pointers technique walks a list with two markers at once. Often one starts at each end and they move toward each other. On a sorted list, this can find two numbers that add up to a target in one pass. It turns many O(n²) loops over every pair into a single O(n) walk. It also checks whether a word reads the same backwards.

## Example

Emma checks if the word level reads the same both ways. One marker starts at each end, and they meet in the middle with every letter matching.

## Why it matters

It is one of the most common tricks for fast list code. Job interviews ask about it a lot.

## Common mistake

Using it on an unsorted list for a sum. The moves only make sense when the list is in order.

## Three principles

- **Two markers.** Often at both ends.
- **Move toward each other.** Based on what they see.
- **One pass.** O(n) instead of O(n²).

## Related terms

- [Array](https://learn.benibix.com/term/development/array)
- [Binary Search](https://learn.benibix.com/term/development/binary-search)
- [Big O Notation](https://learn.benibix.com/term/development/big-o-notation)
- [Algorithm](https://learn.benibix.com/term/development/algorithm)

---

Source: https://learn.benibix.com/term/development/two-pointers
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
