Glossary · Phase 7 · Software engineering
Two pointers
A pattern that moves two positions through data, often inward from both ends of a sorted list, to avoid a nested loop.
Try it now
Most problems give themselves away: sorted input, a count, a range, or a fixed-size window.
Learn it properly
Patterns for coding problems · Two pointers, counting with dictionaries, prefix sums and sliding windows: O(n) answers to classic problems. About 45 minutes.
Other terms from the same lesson
- prefix sum: The total of everything up to each position, so any range's total is one subtraction.
- sliding window: A range that moves along the data, adding what enters and removing what leaves instead of starting over.
Never trained an AI?
Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account.