Interview Prep And Revision
Pattern Recognition Cheat Sheet
You cannot memorize your way through an interview — there are too many possible problems. What you can build is a fast, reliable mapping from the signals in a p
Jr Codex DSA Notes
Level: Advanced Prerequisites: Module 10, Chapter 5 Time to complete: ~25 minutes (reference chapter — expect to return to this often)
Table of Contents
- Why Pattern Recognition Matters More Than Memorizing Solutions
- The Cheat Sheet
- How to Use This Table Under Pressure
- Worked Example: Reading the Signals
- Summary & Next Steps
1. Why Pattern Recognition Matters More Than Memorizing Solutions
You cannot memorize your way through an interview — there are too many possible problems. What you can build is a fast, reliable mapping from the signals in a problem's description to the small number of techniques covered in this curriculum. Every module from 2 through 10 taught you one or two of these techniques deeply; this chapter is the index back into all of them.
2. The Cheat Sheet
| Signal in the Problem | Likely Technique | Module |
|---|---|---|
| Array is sorted (or can be sorted cheaply) | Binary search, or two-pointer | Module 3 (Searching), Module 2 (Two-Pointer) |
| "Find a subarray/substring" matching some condition | Sliding window | Module 2 |
| "Find a pair/triplet" summing to a target, in a sorted array | Two-pointer (opposite ends) | Module 2 |
| Need the top-K, kth largest/smallest, or a running median | Heap / priority queue | Module 7 |
| "Have I seen this before?" / fast duplicate or existence check | Hash map or set | Module 8 |
"Count pairs/occurrences" or need O(1) lookups | Hash map + frequency counting | Module 8 |
| Problem describes a LIFO need — matching brackets, undo, "next greater element" | Stack (often a monotonic stack) | Module 5 |
| Problem describes a FIFO need — process in arrival order, level-by-level | Queue / deque | Module 5 |
| Shortest path in an unweighted graph, or level-order structure | BFS | Module 9 (also Module 7 for tree level-order) |
| "Explore all reachable nodes," connected components, maze/path existence | DFS | Module 9 |
| Traversing/searching a hierarchical (parent-child) structure | Tree traversal (in/pre/post-order or BFS) | Module 7 |
| Structure is explicitly a BST, or values need ordered insert/search/delete | Binary Search Tree | Module 7 |
| "Reverse," "detect a cycle," or "find the middle" in a linked structure | Fast/slow pointers, or in-place pointer rewiring | Module 6 |
| "Explore all combinations/subsets/permutations," possibly with pruning | Backtracking | Module 4 |
| "Count the number of ways," or "min/max cost," with choices that build on smaller versions of the same problem | Dynamic programming (memoization or tabulation) | Module 10 |
| Optimization problem where an early choice never forecloses a better later combination | Greedy | Module 10 |
| Function calls itself with a shrinking input, and the problem is naturally recursive (trees, divide-and-conquer, permutations) | Recursion | Module 4 |
| Need to merge/compare or process elements in a specific order, and no faster structure fits | Sorting first, then a linear/two-pointer pass | Module 3 |
| You're unsure whether a greedy shortcut is actually correct | Test greedy against brute force/DP on small inputs before trusting it | Module 10, Chapter 4 |
3. How to Use This Table Under Pressure
- Read the problem twice before writing anything — the signal words above ("sorted," "subarray," "top-K," "shortest path," "count the ways") are usually present, sometimes disguised in a word problem.
- Name the pattern out loud ("this looks like a sliding window problem because we need the longest substring satisfying a condition") — this is also exactly what Chapter 3 will teach you to do in front of an interviewer.
- Start with the brute-force complexity even if you already suspect the pattern — it gives you a baseline to compare against and something to fall back on if the optimized approach stalls.
- If two rows seem to apply, that's common — many real problems combine two techniques (e.g., hashing to check existence inside a sliding window, or BFS on a tree). Identify which one solves the core bottleneck first.
4. Worked Example: Reading the Signals
Problem: "Given an array of integers, find the length of the longest subarray where the sum of its elements does not exceed a given limit."
Reading the signals: "subarray" + "longest" → sliding window (Module 2) is the primary candidate. Since the array likely contains positive integers (worth clarifying, as Chapter 3 will stress), a variable-size window where you shrink from the left whenever the sum exceeds the limit is a direct application of Module 2, Chapter 4's technique — no hashing, sorting, or DP needed here, because the window's sum can be maintained incrementally in O(1) per step, giving an overall O(n) solution instead of the O(n²) brute force of checking every subarray.
5. Summary & Next Steps
Key Takeaways
- The table above is the fastest path from "unfamiliar problem" to "which module's technique applies" — refer back to it constantly through Chapters 2 and 3.
- Multiple signals often apply to the same problem; identify the technique that resolves the core bottleneck, and treat the rest as supporting detail.
- Naming the pattern explicitly, out loud, before writing code is both a practical shortcut and — as Chapter 3 covers next — exactly what a strong interview answer sounds like.
Concept Check
- What signal words would make you reach for a sliding window instead of a plain nested loop?
- Why might a problem require both hashing and a sliding window at once?
- Pick any three rows in the table and explain, in one sentence each, why that signal implies that technique.
Next Chapter
→ Chapter 2: Mixed Practice Problems
Jr Codex — 1-on-1 Personalized Coaching | Back to Module Index