Begin Algo
Algorithms · 5 lessons

Searching & Two PointersHalving the search space

From plain linear search, to binary search over sorted data, to two pointers and sliding windows — the two array techniques that turn O(n²) into O(n). This is the highest-frequency toolkit in both interviews and day-to-day work.

Why learn Searching & Two Pointers

Where it shows up
git bisect finding the broken commit

Which of a thousand commits introduced the bug? Test the middle one each time and ten steps is enough. That is binary search, and it works on anything ordered.

→ Lesson: Binary Search
"How fast do we have to go to make it?"

Koko eating bananas, the minimum ship capacity: the answer itself is monotonic — faster always still makes it — so you can binary search the answer and just check feasibility each time.

→ Lesson: Binary Search on Answer
"Average over the last 5 minutes"

Data keeps arriving and the window keeps sliding. A sliding window adds each value once and removes it once, instead of recomputing the whole range.

→ Lesson: Sliding Window
Two numbers summing to a target

One pointer from each end, closing in. That drops a factor of n versus the nested loop, and a lot of array problems are variations on it.

→ Lesson: Two Pointers

Lessons

5 lessons