The DSA Interview Playbook

DSA Intermediate 5 min read Published
In this lesson

You’ve learned the patterns. This final lesson turns them into a game plan: how to recognise which pattern a new problem needs, what to say in the interview room, and how to practise without burning out.

The pattern cheat sheet#

Read the problem, look for the clue, reach for the tool.

If the problem says…Think…Lesson
“sorted array”, “find a target”, “minimum value that works”Binary search9
“pair / triplet with sum”, “palindrome”, “in place”Two pointers5
“longest / shortest substring or subarray with…”Sliding window6
“sum of a range”, “subarray sum equals k”Prefix sums + hash map7
“seen before?”, “count”, “group”, “two sum”Hash map / set4
“maximum subarray”Kadane8
“matching brackets”, “undo”, “nested”Stack16
“next greater / smaller”, “temperatures”, “histogram”Monotonic stack17
“cycle in a list”, “middle node”Fast and slow pointers15
“tree depth / path / level”DFS or BFS on trees19
“k largest / smallest”, “median”, “merge k”Heap21
“connected”, “network”, “fewest steps”Graph BFS / DFS22
“grid”, “island”, “spread”, “maze”Flood fill / grid BFS23
“prerequisites”, “order of tasks”Topological sort24
“cheapest route with weights”Dijkstra25
“all combinations / permutations / subsets”Backtracking13
“how many ways”, “min/max cost”, “is it possible”Dynamic programming26, 27
“intervals”, “meetings”, “schedule”Sort + greedy sweep28

Input size is a giant hint. n ≤ 20: backtracking is fine. n ≤ 1,000: O(n²) works. n up to 100,000 or more: you need O(n log n) or O(n).

Want to drill this? Play Pattern Detective in the Brain Games: you read a problem in one line and pick the pattern before the timer runs out.

The 6-step method for any coding question#

  1. Understand. Repeat the problem in your own words. Ask about input size, empty input, duplicates, negative numbers, and what to return when there’s no answer.
  2. Examples. Work through one normal example and one edge case by hand. This often reveals the pattern.
  3. Brute force first. Say the simple solution and its complexity out loud: “Checking every pair is O(n²).” It proves you can solve it and gives you a baseline.
  4. Optimise. Ask: “What work am I repeating?” Then reach for the cheat sheet: a hash map to remember, sorting to bring things together, a heap for the best-so-far, DP for repeated subproblems.
  5. Code. Clean names, small helper functions, no clever tricks you can’t explain.
  6. Test. Walk through your code with the example, line by line, then try the edge cases. Fix bugs calmly: finding your own bug is a positive signal.

How to talk while you code#

Interviewers can’t read your mind. Silence feels like being stuck, even when you’re not. Narrate:

  • “I’ll use a dictionary mapping each value to its index so lookups are O(1).”
  • “This loop moves the right pointer; the inner while shrinks the window when it becomes invalid.”
  • “I’m not sure about this edge case. Let me check it with an empty list.”

If you’re stuck, say what you’re thinking: “Sorting would give O(n log n). Could a hash map get O(n)?” Interviewers often give hints, and taking a hint well is a skill they score.

Complexity: always say it#

Finish every solution with time and space complexity and why:

def two_sum(nums, target):
    seen = {}                          # value -> index
    for i, x in enumerate(nums):
        if target - x in seen:
            return [seen[target - x], i]
        seen[x] = i
    return []

print(two_sum([2, 7, 11, 15], 9))  # [0, 1]

“One pass over n numbers with O(1) dictionary operations: O(n) time. The dictionary may store n items: O(n) space.”

Edge cases checklist#

Run through this list before you say “done”:

  • Empty input, a single element, two elements.
  • All items the same; already sorted; sorted in reverse.
  • Negative numbers and zero.
  • Very large input (would your recursion hit the limit?).
  • No valid answer (what do you return?).

Beyond the code#

  • Behavioural questions matter too, especially at Amazon (leadership principles). Prepare 5 short stories using STAR: Situation, Task, Action, Result.
  • Ask good questions at the end: about the team, how they review code, what a first project might look like.
  • System design appears for experienced roles; for freshers and interns, DSA and fundamentals dominate.

A calm 8-week practice plan#

Thirty to sixty focused minutes a day beats a 10-hour weekend.

WeekFocusPractise
1Arrays, strings, hashing, Big O8 easy problems
2Two pointers, sliding window, prefix sums8 problems, mostly easy
3Binary search, sorting, stacks8 problems, first mediums
4Linked lists, recursion, backtracking8 problems
5Trees, BST, heaps8 problems, mostly medium
6Graphs, grids, topological sort8 problems
7Dynamic programming, greedy, intervals8 problems
8Mixed review and timed mock interviews2 mocks + revisit missed problems

Rules that make it stick:

  • Try for 20–30 minutes, then read a hint, not the full solution.
  • Re-solve every problem you needed help with three days later, from scratch.
  • Keep a log: problem, pattern, the key idea in one sentence.
  • Take brain breaks. A 2-minute game resets your focus better than scrolling.

Where to practise on VitalStack#

  • The Interview Problems page lists classic questions with their pattern, difficulty and companies that commonly ask them. Filter by pattern to drill one technique at a time, or hit “Random problem” for a surprise.
  • Every lesson in this course has a live visualizer: change the input and watch the algorithm think. Each one you finish earns XP.
  • The Brain Games page trains binary search, brackets, Big O and pattern spotting in 2 minutes.

Interview corner#

Companies like Google, Amazon, Microsoft, Meta, Apple, Adobe, Flipkart, Uber and Goldman Sachs all run DSA rounds, and the patterns repeat. Interviewers consistently say the same thing: they care less about a perfect answer and more about clear thinking, communication and testing. A brute-force solution explained well beats a half-finished clever one.

Common mistakes#

  • Coding immediately without clarifying or giving examples.
  • Going silent for minutes at a time.
  • Skipping the brute force and getting lost chasing the optimal answer.
  • Not testing the code before saying “done”.
  • Memorising solutions instead of patterns: a small twist breaks memorised answers.

Exercise#

  1. Pick three problems from the Interview Problems page with different patterns. For each, write only the clue you spotted and the tool you’d use.
  2. Solve one of them out loud, recording yourself. Listen back: were there long silences?
  3. Write your own one-page cheat sheet from memory. Compare it with the table above.

Summary#

  • Match problem clues to patterns using the cheat sheet; input size hints at the needed complexity.
  • Follow the 6 steps: understand, examples, brute force, optimise, code, test.
  • Talk through your thinking and always state complexity.
  • Practise daily with spaced repetition, and take brain breaks.

Congratulations on finishing the DSA course! Head to the Interview Problems page and start your streak.

Quick quiz

3 questions. Check what stuck and earn 2 XP for each right answer.

1What should you do before coding in an interview?
2After coding, you should…
3Which is an important edge case to check?

Progress is saved in this browser. Create a free account to keep it on every device.