mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2026-10-25 17:42:27 +08:00
* refactor: clean to roadmap content * refactor: move shared helpers into scripts/lib
8 lines
812 B
Markdown
8 lines
812 B
Markdown
# Two Pointers
|
|
|
|
Two pointers is the first real pattern you will learn, and it is one of the most reusable. The idea is simple: instead of checking every pair of elements with nested loops, you place one pointer at each end of a sorted structure and move them toward each other based on a condition. This brings many O(n²) problems down to O(n). Most problems here require a sorted input, so sorting is often the first step. Mastering this pattern also prepares you for fast and slow pointers, which appear in linked list problems later.
|
|
|
|
Visit the following resources to learn more:
|
|
|
|
- [@article@Mastering Problem Solving: Two Pointers](https://medium.com/@elfrmkr98/mastering-problem-solving-two-pointers-technique-23dafb17e90b)
|
|
- [@video@Two Pointers in 7 minutes](https://www.youtube.com/watch?v=QzZ7nmouLTI) |