Pattern Recognition Quiz
12-Week DSA Roadmap
Achievements
🧠 How to Think Through DSA Problems
A battle-tested framework for recognising patterns, drilling down on any problem, and coding clean Java solutions under pressure.
Before writing a single line, make sure you truly understand what's being asked.
- Restate the problem in your own words out loud.
- Identify: What is the input? What is the exact output?
- Ask about constraints: array size, value range, can there be negatives? duplicates? null?
- Walk through the provided examples manually — don't trust that you understand without doing this.
- Create 1-2 of your own examples, including an edge case (empty input, single element, all same values).
Map what you see in the problem to a known algorithm pattern. Ask yourself these questions in order:
- Is the input sorted? → Binary Search or Two Pointers
- Contiguous subarray/substring with a condition? → Sliding Window
- Count/sum subarrays? → Prefix Sum + HashMap
- Shortest path, minimum steps, level-by-level? → BFS
- Connected components, cycle detection, all paths? → DFS / Union-Find
- Dependencies between tasks? → Topological Sort
- Optimal sub-problem overlapping? → Dynamic Programming
- All combinations, permutations, or subsets? → Backtracking
- K largest/smallest elements? → Heap (Priority Queue)
- Next greater/smaller to the left/right? → Monotonic Stack
- Prefix of words, autocomplete? → Trie
- Weighted shortest path? → Dijkstra (no negative) / Bellman-Ford (negative ok)
Before opening an IDE, state your approach in plain English, step by step.
- Say "I'll use [pattern] because [reason]."
- Describe the data structures you need and why (e.g. "I need a HashMap to track char frequencies in O(1)").
- Walk through your algorithm on the example input — trace it mentally or on paper.
- State your time and space complexity. Is it good enough? What are the constraints?
- Only proceed to coding once you can trace through the algorithm correctly on paper.
Write clean, readable code. Follow this Java-specific checklist:
- Handle edge cases first:
if (nums == null || nums.length == 0) return ...; - Use descriptive variable names:
left, right, windowSum, maxLen— noti, j, x, y. - Prefer
int mid = left + (right - left) / 2;over(left + right) / 2to avoid integer overflow. - For DFS/BFS: always mark visited before enqueueing, not after dequeuing.
- For DP: always think "do I need 1D or 2D? Can I roll it into 1D?"
- Think about what to return when the answer doesn't exist (e.g., -1 vs empty list vs 0).
Never say "I think it works." Systematically test these cases:
- Empty input:
[],"",null - Single element:
[5] - All same values:
[1,1,1,1] - Already sorted / reverse sorted
- Negative numbers / zeros
- Maximum input size (does it TLE?)
- The provided examples (run through your code step by step)
When you're stuck, run through this checklist in order:
- What is the brute force? How slow is it? (O(n²)? O(2ⁿ)?)
- What is the bottleneck — what computation is repeated?
- Can you use a data structure to make repeated lookups O(1)? → HashMap, Set, Heap
- Can you precompute something? → Prefix Sum, Sorted Array
- Can you solve a simpler subproblem and build up? → DP
- Can you discard half the search space? → Binary Search
- Can you process things in a specific order? → Greedy, Topological Sort
Interviewers grade communication as much as correctness. Use this script:
- "Let me restate the problem:" — repeat it back to confirm understanding.
- "My initial edge cases are:" — null check, empty input, single element.
- "My first thought is brute force — that would be O(?) because..."
- "I notice [observation] — this suggests [pattern] because..."
- "My approach will be: [algorithm steps in English]."
- "The time complexity is O(?) because... and space is O(?) because..."
- "Let me code this up. I'll start with the edge case check."
- While coding: narrate what each block does: "This loop slides the window..."
- After coding: "Let me trace through the first example..."
- At the end: "I'd also test: empty input, single element, all negatives."
- Integer overflow: use
longwhen summing large arrays.int mid = left + (right-left)/2not(left+right)/2. - Off-by-one in binary search: think "does this need left=0, right=n or right=n-1?" Match your loop invariant to your return.
- Null checks in trees: always handle
if (node == null) return;as your first line in DFS. - ConcurrentModificationException: never modify a collection while iterating it. Use an iterator or collect into a separate list.
- Stack overflow in DFS: for very deep recursion (n > 10,000), convert to iterative with an explicit Stack.
- HashMap default value: use
map.getOrDefault(key, 0)notmap.get(key)(which returns null for missing keys). - PriorityQueue ordering: Java's PriorityQueue is a min-heap by default. For max-heap:
new PriorityQueue<>(Collections.reverseOrder()). - char to int:
'a' - 'a' = 0, so usec - 'a'to get 0-25 index for letter arrays.
For a 45-minute interview with one coding problem:
- 0-5 min: Understand, ask clarifying questions, write examples.
- 5-10 min: Identify pattern, state brute force, optimize.
- 10-30 min: Code the solution cleanly.
- 30-38 min: Test with examples + edge cases. Fix bugs.
- 38-45 min: Discuss time/space complexity, potential improvements.
You WILL see problems you haven't seen before. That's the point. Here's how to handle them:
- Don't panic. Every novel problem is a combination of known patterns.
- Identify the data structures involved (array? tree? graph? string?).
- Think about what operation is being repeated — that repetition is your bottleneck.
- Ask: "If the input were tiny (n=3), how would I solve it by hand?"
- Ask: "What information do I need at each step that I'm currently recomputing?"
- Write the brute force first. Often the interviewer will accept O(n²) with the right intuition explained.
- Optimize step by step: can a HashMap help? Can I sort first? Can I use a sliding window?
🗓️ Your 20-Day DSA God Run
You have 20 days of pure focus. This is the exact sequence to go from decent to dangerous.
🏗️ High-Level System Design (HLD)
The 7-step RSCALED framework for designing scalable, resilient distributed systems.
🔷 Low-Level Object-Oriented Design (LLD)
Object-oriented design patterns, thread safety, and clean Java class hierarchies.
📝 Mistake Log
Track every mistake, tag the pattern, and review them daily. This is your most powerful learning tool.