Data Structures & Algorithms

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

JrCodex·5 min read

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

  1. Why Pattern Recognition Matters More Than Memorizing Solutions
  2. The Cheat Sheet
  3. How to Use This Table Under Pressure
  4. Worked Example: Reading the Signals
  5. 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 ProblemLikely TechniqueModule
Array is sorted (or can be sorted cheaply)Binary search, or two-pointerModule 3 (Searching), Module 2 (Two-Pointer)
"Find a subarray/substring" matching some conditionSliding windowModule 2
"Find a pair/triplet" summing to a target, in a sorted arrayTwo-pointer (opposite ends)Module 2
Need the top-K, kth largest/smallest, or a running medianHeap / priority queueModule 7
"Have I seen this before?" / fast duplicate or existence checkHash map or setModule 8
"Count pairs/occurrences" or need O(1) lookupsHash map + frequency countingModule 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-levelQueue / dequeModule 5
Shortest path in an unweighted graph, or level-order structureBFSModule 9 (also Module 7 for tree level-order)
"Explore all reachable nodes," connected components, maze/path existenceDFSModule 9
Traversing/searching a hierarchical (parent-child) structureTree traversal (in/pre/post-order or BFS)Module 7
Structure is explicitly a BST, or values need ordered insert/search/deleteBinary Search TreeModule 7
"Reverse," "detect a cycle," or "find the middle" in a linked structureFast/slow pointers, or in-place pointer rewiringModule 6
"Explore all combinations/subsets/permutations," possibly with pruningBacktrackingModule 4
"Count the number of ways," or "min/max cost," with choices that build on smaller versions of the same problemDynamic programming (memoization or tabulation)Module 10
Optimization problem where an early choice never forecloses a better later combinationGreedyModule 10
Function calls itself with a shrinking input, and the problem is naturally recursive (trees, divide-and-conquer, permutations)RecursionModule 4
Need to merge/compare or process elements in a specific order, and no faster structure fitsSorting first, then a linear/two-pointer passModule 3
You're unsure whether a greedy shortcut is actually correctTest greedy against brute force/DP on small inputs before trusting itModule 10, Chapter 4

3. How to Use This Table Under Pressure

  1. 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.
  2. 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.
  3. 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.
  4. 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

  1. What signal words would make you reach for a sliding window instead of a plain nested loop?
  2. Why might a problem require both hashing and a sliding window at once?
  3. 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