Patterns

Most problems are a small number of ideas in different clothes. Learn the idea once and the problems get easier. They are listed in a sensible order: each one builds on the ones before it.

  1. 017 problems

    Hashing and counting

    Trade memory for speed by remembering what you have already seen.

  2. 022 problems

    Prefix sums

    Precompute running totals so range questions become subtraction.

  3. 035 problems

    Two pointers

    Walk two positions through the data instead of nesting loops.

  4. 044 problems

    Sliding window

    Keep a moving range valid while you scan once.

  5. 059 problems

    Stack

    Last in, first out. Matching, nesting and next-greater problems.

  6. 065 problems

    Binary search

    Halve the search space whenever the answer is monotonic.

  7. 076 problems

    Linked list

    Pointer manipulation, fast and slow pointers, in-place rewiring.

  8. 086 problems

    Intervals

    Sort by start, then sweep and merge.

  9. 0914 problems

    Trees and recursion

    Depth-first traversal and recursive structure.

  10. 105 problems

    Breadth-first search

    Level by level and shortest path on unweighted graphs.

  11. 114 problems

    Backtracking

    Build choices one at a time and undo them when they fail.

  12. 128 problems

    Graph traversal

    Connectivity, components and cycles.

  13. 134 problems

    Topological sort

    Order tasks that depend on each other.

  14. 141 problems

    Union-find

    Track which items belong to the same group.

  15. 153 problems

    Shortest paths

    Weighted graphs with Dijkstra and its relatives.

  16. 164 problems

    Trie

    Prefix trees for words and autocomplete.

  17. 178 problems

    Heap and top-K

    Keep the best K items without sorting everything.

  18. 182 problems

    Greedy

    Take the locally best step and prove it is safe.

  19. 1915 problems

    Dynamic programming

    Reuse answers to overlapping subproblems.

  20. 207 problems

    Bits and math

    Bit tricks and number properties.

  21. 2110 problems

    Matrix and parsing

    Grids, simulation and careful string handling.

  22. 2224 problems

    Design a data structure

    Build a class with the right operations and complexity.