0 of 30 done
Start herePattern: Prefix Sum

15 recurring problem-solving patterns, revised to university / high-school course quality per the course standard. Each pattern has prerequisites, observable outcomes, motivation, definitions, a step-by-step mechanism, a complete runnable example, independent practice with checks, and a demonstrable finish line. The teaching moves borrow from DSA 02-data-structures — motivation before machinery, definitions before terminology, concrete examples with predictions, and independent implementation tasks.

15 recurring problem-solving patterns, based on “LeetCode was HARD until I Learned these 15 Patterns” (Ashish Pratap Singh, blog.algomaster.io), reworked and expanded with the mechanics already written up in the parent DSA notes. The pitch of the source article, worth keeping in mind: LeetCode is less about the number of problems solved and more about how many patterns you recognize — most “new” problems are a known pattern wearing a different costume.

Several of these link back to a foundations note for the underlying mechanics (traversal orders, DFS, BFS) rather than re-explaining them — this folder is about recognizing which pattern applies and why, not re-deriving the algorithm from scratch.

The 15 patterns

Roughly ordered easiest to hardest to first get comfortable with — later ones lean on earlier ones (backtracking on DFS, for instance).

  1. prefix-sum — [Beginner] — O(1) range-sum queries after O(n) preprocessing
  2. two-pointers — [Beginner] — converge from both ends of sorted data
  3. sliding-window — [Intermediate] — contiguous subarray/substring, same-direction pointers
  4. fast-slow-pointers — [Intermediate] — cycle detection, O(1) space
  5. linked-list-reversal — [Intermediate] — in-place pointer rewiring
  6. monotonic-stack — [Intermediate] — next greater/smaller element in O(n)
  7. top-k-elements — [Intermediate] — heap-based top/bottom k
  8. overlapping-intervals — [Intermediate] — sort by start, merge in one pass
  9. modified-binary-search — [Advanced] — binary search on rotated/modified sorted data
  10. binary-tree-traversal-pattern — [Intermediate] — choosing pre/in/postorder for the problem at hand
  11. dfs-pattern — [Intermediate] — explore every path/branch, topological sort
  12. bfs-pattern — [Intermediate] — shortest path/level order in unweighted structures
  13. matrix-traversal — [Intermediate] — grids as implicit graphs
  14. backtracking — [Advanced] — explore + undo, generate all valid arrangements
  15. dynamic-programming — [Advanced] — cache overlapping subproblems, memoization vs tabulation

Question banks

One bank per lesson: micro-questions with the answers hidden behind toggles, for closed-book recall rather than reading. Method explained in the arrays bank.


↑ Back to Data Structures & Algorithms