AlgoPlusAlgoPlus
← All modules

Problem-Solving Patterns

How to think about a problem before you code it. · 14 topics

Recursion→
The call tree unfolds and folds (Fibonacci).
Dynamic Programming→
Fill a table, reuse subproblems (coin change).
Sliding Window→
A window slides across the array, no re-scan.
Backtracking→
Explore the decision tree, prune dead ends (N-Queens).
Two Pointers→
Converging pointers on a sorted array (pair sum).
Greedy→
Take the locally best choice each step (activity selection).
Kadane's Algorithm→
Maximum-sum contiguous subarray in one pass.
Cyclic Sort→
Sort 1..n in place by swapping each value home.
Merge Intervals→
Sort by start, fuse overlapping intervals.
Prefix Sums→
Precompute totals; range sum in O(1).
Monotonic Stack→
Next greater element via a decreasing stack.
Fast & Slow Pointers→
Cycle detection (tortoise and hare).
Bit Manipulation→
Count set bits with n & (n−1).
Binary Search on Answer→
Search a monotonic answer space (integer √).