Skip to content

Algorithm Patterns

Mastering algorithmic patterns is essential for solving coding challenges efficiently. Instead of memorizing individual solutions, learning these patterns helps you recognize problem types, apply the right technique, and build problem-solving intuition.


Pattern reference

Pattern Description Links
Sliding Window Optimizes problems involving contiguous sequences Notes · LC 3
Dynamic Programming Breaks complex problems into overlapping subproblems Notes · LC 322
Two Pointers Uses multiple pointers to traverse data structures Notes · LC 15
Fast & Slow Pointers Detects cycles or finds specific positions with different speeds Notes · LC 141
Backtracking Explores all possible solutions by building candidates incrementally Notes · LC 78
Binary Search on Answer Uses binary search to efficiently find optimal values Notes · LC 875
Greedy Makes locally optimal choices at each step Notes · LC 45
Heap / Priority Queue Maintains elements in sorted order for efficient extreme access Notes · LC 347
Monotonic Stack Maintains stack elements in monotonic order Notes · LC 739
Graph Traversal (BFS/DFS) Systematic graph exploration Notes · LC 200
Trie (Prefix Tree) Tree structure for efficient string prefix operations Notes · LC 208
Space Complexity Measuring and improving memory usage Notes · LC 73

How to use this guide

Each pattern section includes:

  1. Conceptual overview — when and why to use the pattern
  2. Step-by-step approach — how to apply it systematically
  3. LeetCode examples — real problems with solutions
  4. Implementation details — code walkthroughs

Start with a pattern that interests you, work through the examples, and practice applying the approach to similar problems.