Skip to content

Latest commit

 

History

History
38 lines (35 loc) · 5.17 KB

PATTERNS.md

File metadata and controls

38 lines (35 loc) · 5.17 KB

16 Core Algorithmic Patterns Taxonomy

Every solution in this repository is organised around one of these sixteen cross-cutting patterns. Each entry lists representative problems to start with; the full topic-by-topic roadmap lives in the README.

  1. Two Pointers & Sliding Window — converging pointers over sorted data, or a window that maintains an invariant while it expands and contracts. → 1. Two Sum · 42. Trapping Rain Water · 167. Two Sum II
  2. Fast & Slow Pointers (Cycle Detection) — two pointers at different speeds to detect cycles, find midpoints, or locate an entry point without extra space. → 148. Sort List · 287. Find the Duplicate Number
  3. Merge Intervals — sort by start, then sweep while comparing each interval's start against the running end. → 56. Merge Intervals · 435. Non-overlapping Intervals
  4. Monotonic Stack & Deque — keep candidates in monotonic order so each element is pushed and popped at most once. → 84. Largest Rectangle in Histogram · 239. Sliding Window Maximum
  5. Tree DFS & BFS Traversals — recursive pre/in/post-order passes, or level-order queues for depth-wise answers. → 94. Binary Tree Inorder Traversal · 102. Level Order Traversal · 199. Right Side View
  6. Graph Topological Sort & DSU — ordering under dependency constraints, or union-find for connectivity and cycle detection. → 207. Course Schedule · 547. Number of Provinces · 684. Redundant Connection
  7. Dynamic Programming (State Compression) — define the state, the transition, and the base case, then compress dimensions you no longer read. → 322. Coin Change · 300. Longest Increasing Subsequence · 1143. Longest Common Subsequence
  8. Backtracking & Branch Pruning — choose, explore, un-choose, and cut branches that cannot lead to a valid answer. → 51. N-Queens · 40. Combination Sum II · 37. Sudoku Solver
  9. Binary Search on Sorted & Rotated Arrays — halve the search space by exploiting order, including rotated pivots and answer-space search. → 704. Binary Search · 33. Search in Rotated Sorted Array
  10. Heaps & Top-K Selection — a bounded heap or quickselect keeps only the k elements that matter. → 215. Kth Largest Element · 347. Top K Frequent Elements · 23. Merge k Sorted Lists
  11. Trie & Prefix Search — a character-indexed tree answers prefix queries in O(L) and shares work across words. → 208. Implement Trie · 211. Add and Search Words
  12. Greedy Scan & Kadane's Algorithm — commit to the locally optimal choice and prove the running state never needs to look back. → 53. Maximum Subarray · 55. Jump Game
  13. Prefix Sums & Difference Arrays — precompute cumulative state so range queries and range updates become O(1). → 303. Range Sum Query Immutable · 560. Subarray Sum Equals K · 370. Range Addition
  14. Grid Traversal (BFS/DFS on Matrices) — treat cells as nodes and four-directional moves as edges, in place when possible. → 200. Number of Islands · 130. Surrounded Regions · 695. Max Area of Island
  15. Design Data Structures (Hash + Linked List) — combine a map for O(1) lookup with a list for O(1) eviction or ordering. → 146. LRU Cache · 155. Min Stack
  16. Bit Manipulation & XOR — exploit word-level parallelism, XOR cancellation, and bit counting instead of per-element work. → 136. Single Number · 137. Single Number II · 191. Number of 1 Bits

These sixteen are cross-cutting families, not an exhaustive labelling: every problem is additionally filed under its own LeetCode topic in the README roadmap.