Algorithms

Two pointers

A technique that walks a list with 2 indexes at once, for example one from each end, moving them by a rule until they meet.

Example

For the largest container in a list of 9 heights, i starts at 0 and j at 8, and the shorter one moves: 8 steps instead of 36 pairs.

Test yourself: Two pointers

Largest container

The capacity of 2 boards is min(ht[i], ht[j]) × (___).

Lessons that use it

More algorithms terms

All terms →

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.