Documentation Index
Fetch the complete documentation index at: https://resources.devweekends.com/llms.txt
Use this file to discover all available pages before exploring further.
Pattern Recognition Cheatsheet (Read This First)
Why Learn by Patterns?
Most coding interviews test the same 22 core patterns repeatedly. Solving 1000 random LeetCode problems without a framework is like learning a language by memorizing individual sentences — you never learn the grammar. Patterns are the grammar of algorithmic problem-solving. Understanding them helps you:- Recognize problem types in seconds by matching keywords and constraints to a known pattern
- Apply proven templates to problems you have never seen before
- Optimize solutions systematically by knowing what each pattern trades off (time vs space, simplicity vs generality)
- Explain your thought process clearly in interviews, which matters as much as getting the right answer
Pattern Categories
Array & String Patterns
Search & Sort
Graph Patterns
Dynamic Programming
Data Structure Patterns
Advanced Techniques
Pattern Selection Flowchart
Use this decision tree when you encounter a new problem:Quick Pattern Recognition Cheat Sheet
Keywords that Signal Each Pattern
Keywords that Signal Each Pattern
| If you see… | Think… |
|---|---|
| “sorted array”, “find pair with sum” | Two Pointers |
| ”contiguous subarray”, “window of size k” | Sliding Window |
| ”find in sorted”, “minimize/maximize” | Binary Search |
| ”frequency”, “anagram”, “contains” | HashMap |
| ”all paths”, “connected components” | DFS |
| ”shortest path”, “level order” | BFS |
| ”maximum/minimum with constraints” | Dynamic Programming |
| ”generate all”, “permutations”, “combinations” | Backtracking |
| ”optimal choice at each step” | Greedy |
| ”k largest/smallest”, “merge sorted” | Heap |
| ”matching brackets”, “undo” | Stack |
| ”prefix/autocomplete” | Trie |
| ”connected groups”, “union/merge” | Union Find |
Memory Tricks (Mnemonics)
Memory Tricks (Mnemonics)
- Sorted array?
- Two elements needed?
- Avoid nested loops?
- Move based on comparison?
- Pairs/Triplets?
- Space O(1) possible?
- Subarray/Substring problem?
- Length constraints?
- Iterate once?
- Dynamic window possible?
- Expand and shrink?
- Decision at each step?
- Recurrence relation possible?
- Every subproblem needed?
- Answer from subproblems?
- Duplicate subproblems?
Learning Path
Foundation (Week 1-2)
Core Patterns (Week 3-4)
Intermediate (Week 5-6)
8-Week Study Calendar
- Week 1-2: Foundation
- Week 3-4: Core
- Week 5-6: Intermediate
- Week 7-8: Advanced
| Day | Topic | Problems to Solve |
|---|---|---|
| 1 | Two Pointers Intro | Two Sum II, Valid Palindrome |
| 2 | Two Pointers Practice | 3Sum, Container With Most Water |
| 3 | Sliding Window Fixed | Max Sum Subarray, Avg of Subarrays |
| 4 | Sliding Window Variable | Longest Substring Without Repeat |
| 5 | HashMap Basics | Two Sum, Contains Duplicate |
| 6 | HashMap + Frequency | Valid Anagram, Group Anagrams |
| 7 | Review + Mixed Practice | Solve 3 random problems |
Pattern Difficulty Matrix
| Pattern | Difficulty | Frequency | Time to Learn | Interview Importance |
|---|---|---|---|---|
| Two Pointers | Easy | Very High | 2-3 days | Very High |
| Sliding Window | Easy | Very High | 2-3 days | Very High |
| HashMap | Easy | Very High | 1-2 days | Very High |
| Binary Search | Medium | Very High | 3-4 days | Very High |
| DFS/BFS | Medium | High | 4-5 days | Very High |
| Stack/Queue | Easy | High | 2-3 days | High |
| Heap | Medium | Medium | 3-4 days | High |
| Dynamic Programming | Hard | Very High | 2-3 weeks | Very High |
| Backtracking | Medium | Medium | 4-5 days | High |
| Greedy | Medium | Medium | 3-4 days | Medium |
| Trie | Medium | Low | 2-3 days | Medium |
| Union Find | Medium | Medium | 3-4 days | High |
| Monotonic Stack | Hard | Low | 3-4 days | Medium |
| Bit Manipulation | Medium | Low | 2-3 days | Low |
Company-Wise Pattern Frequency
- Google
- Amazon
- Meta
- Microsoft
- Dynamic Programming (25%)
- Graph Algorithms (20%)
- Binary Search (15%)
- Two Pointers/Sliding Window (15%)
- HashMap/HashSet (10%)
- Others (15%)
Success Tips
Spaced Repetition
Teach Others
Time Yourself
Debug Without IDE
What To Do When The Pattern Is Not Obvious
You will get problems where the pattern is not in the cheatsheet. Here is the exact 6-step playbook senior engineers run when stuck. Use it as a script.Restate the problem in one sentence
Identify the input shape
Identify the goal type
Solve brute force out loud
Look for redundancy
Interview Q&A: Pattern Recognition Under Pressure
Walk me through how you decide which DSA pattern to apply when you read a new problem.
Walk me through how you decide which DSA pattern to apply when you read a new problem.
- Restate in one sentence to confirm understanding. Repeat the problem in your own words. This buys time and confirms input/output shape.
- Read constraints before solution. “n up to 10 to the 5” demands O(n log n) or better. “n up to 20” hints at exponential / bitmask DP / backtracking. The constraints narrow the search dramatically.
- Match shape to candidate patterns. Array (sorted? sliding? prefix?), graph (DFS / BFS / Union Find?), tree (recursion?), string (sliding window? hash?). Pick 2-3 candidates.
- State the brute force explicitly. Always. It anchors your reasoning and reveals the redundancy to remove.
- Look for invariants the pattern needs. Sliding window needs monotonic state. Two pointers needs sorted (or sortable) input. Greedy needs an exchange argument. If the invariant fails, the pattern fails.
- Code the pattern and verify with the smallest example. Trace through n=2 or n=3 by hand. If output matches, scale up. If not, the pattern was wrong — back to step 3.
- Restate: count contiguous subarrays summing to K.
- Constraints: n up to 2 * 10 to the 4, values from negative 1000 to 1000. Quadratic is borderline acceptable but optimal is expected.
- Shape candidates: Array + “contiguous subarray” + sum -> Sliding Window? But values can be negative, so sliding window is out. Prefix Sum + HashMap is the universal tool.
- Brute force: all pairs O(n squared).
- Optimization: for each prefix sum P, count how many earlier prefix sums equal P - K. HashMap of prefix sums to frequency.
- Pattern matched: Prefix Sum + HashMap. O(n) time, O(n) space.
- “I look at the data structure and pick a pattern.” Too shallow. Constraints + goal + invariants matter more than shape alone.
- “I try every pattern until one works.” Time is finite. Narrowing to 2-3 candidates is the skill.
- “I see if I have solved this exact problem before.” Pattern matching, not pattern reasoning. Fails on rephrased problems.
- LC 560 (Subarray Sum Equals K), LC 1248 (Count Number of Nice Subarrays) — both prefix sum + HashMap.
- “How to Approach a Problem” — NeetCode YouTube playlist.
How do you avoid getting stuck for 20 minutes if you do not see the pattern immediately?
How do you avoid getting stuck for 20 minutes if you do not see the pattern immediately?
- Set a 3-minute “ideation budget.” If you do not have a candidate pattern after 3 minutes, switch tactic: stop staring, start computing.
- Compute a small example by hand. Walk through n=3 or n=4. The structure of your manual solution usually reveals the pattern within 60 seconds.
- Narrate continuously. Silence is the enemy. “I see this looks like a graph problem because there are dependencies. BFS or DFS? The problem asks for shortest path, so BFS.” Even partial narration earns credit and often unsticks you.
- Reach for a brute force. Code the O(n squared) or exponential solution. Once you see the redundancy, the optimization pattern often becomes obvious. “I am re-summing the same window, so I can use prefix sum.”
- Ask the interviewer one targeted question. “Are values bounded?” “Can the array be modified?” “Is there a constraint on space?” Each question narrows candidate patterns. Asking 5 vague questions hurts; asking 1 sharp question helps.
- Pick a wrong pattern and proceed anyway. Even a wrong pattern often produces partial credit. Senior interviewers grade your process and recovery, not just final correctness.
- First instinct: sliding window with exactly K distinct? Try to maintain invariant. After 60 seconds you realize “exactly K” is not monotonic — expanding can add a new distinct, shrinking might keep distinct count the same.
- Pivot: narrate “The exact-K window is not monotonic. Let me try at-most-K instead — that one is monotonic.”
- Insight: exactly(K) = atMost(K) - atMost(K-1). Sliding window for atMost is standard.
- Total time: under 8 minutes if you narrate. 25 minutes if you stay silent.
- “I just keep thinking until I see it.” Dangerous. After 5 minutes of silence, you have lost the interviewer.
- “I write the brute force and ship it.” OK for partial credit but you must explicitly narrate the optimization path even if you do not finish.
- “I ask for hints right away.” Hints are fine after 5-10 minutes of visible effort. Earlier signals you did not try.
- LC 992 (K Different), LC 904 (Fruit Into Baskets), LC 1248 (Nice Subarrays) — all the atMost decomposition family.
- “How to Solve It” by George Polya — the original problem-solving framework.
When you have multiple candidate patterns, how do you choose between them under interview time pressure?
When you have multiple candidate patterns, how do you choose between them under interview time pressure?
- Compare time and space complexity for each candidate. Often one dominates the other. HashMap O(n) time + O(n) space vs sorting + Two Pointers O(n log n) time + O(1) space — pick based on stated constraint.
- Pick the simpler implementation when complexity ties. Under interview pressure, fewer moving parts means fewer bugs. Prefer prefix sum + HashMap over a custom segment tree if both work.
- Pick the pattern you have practiced more recently. If sliding window and prefix sum both fit, go with whichever feels mechanical. You are racing the clock.
- State the trade-off out loud. “Both work. I am picking sliding window because it is O(1) space, which the constraints emphasize.” This shows judgment, not just code.
- Verify with the smallest example. Even after picking, trace through n=3 to confirm the chosen pattern’s invariant holds.
- Candidate A: Sliding Window. O(n) time, O(1) space. Works because all values positive (monotonic).
- Candidate B: Prefix Sum + Binary Search. O(n log n), O(n) space. Works for any sign.
- Decision: sliding window wins on both axes for the stated constraint. Pick it. Mention B as alternative when discussing trade-offs.
- “I always pick the lowest time complexity.” Ignores space and constants. O(n log n) with low constants often beats O(n) with high constants in practice.
- “I pick the most clever pattern.” Cleverness costs implementation time and bugs. Boring is good in interviews.
- “I pick whichever pattern I see first.” Skips the comparison, signals shallow analysis.
- LC 209, LC 862 (Shortest Subarray with Sum at Least K, the negative-values variant).
- “Algorithm Design Manual” by Steven Skiena — chapters on trade-offs between algorithm classes.
What is your strategy for the last 10 minutes of an interview if you have not finished?
What is your strategy for the last 10 minutes of an interview if you have not finished?
- Stop adding new code. New code introduces new bugs. Focus on what exists.
- Trace through your code with one example out loud. Catch off-by-ones, edge cases, and missed initializations. Senior interviewers reward visible verification.
- State known limitations. “This handles the positive case but I have not verified negatives — let me add that test.” Owning gaps beats hiding them.
- Discuss optimization paths even if you cannot implement them. “If I had more time I would replace the linear scan with binary search to get O(n log n).” Shows depth without overcommitting.
- Prepare the closing summary. End with: “My solution is O(n) time, O(n) space, handles positives and negatives, and would need adjustment for streaming input. Known edge cases: empty array, all duplicates.”
- Stop coding. The shrink loop has a bug you have not located. Fixing it under time pressure risks breaking what works.
- Trace example “ADOBECODEBANC” with target “ABC” by hand. Notice you are not collapsing repeated frequency comparisons.
- Articulate the optimization: “I should track ‘matches’ instead of comparing full frequency maps each step. That gets us to O(n + m).”
- Closing: “Current code is O(n*m), correct for the example. The fix is the matches counter, which I can sketch but not fully implement in remaining time.”
>= when it should be >, or vice versa. Always identify your highest-risk line.)- “I rush to add features.” Adds bugs. Last 10 minutes is for stabilization, not exploration.
- “I stay silent and keep typing.” Interviewers grade thinking, not code. Narrate.
- “I claim it works without verifying.” If you cannot trace it, you do not know.
- “Cracking the Coding Interview” by Gayle McDowell — chapter on time management.
- NeetCode “Mock Interview” series on YouTube for closing-time strategies.