📊 We use cookies & analytics to improve your experience. Learn more
Latest

Interview DSA Crash Course Module 1 · Lesson 2 of 15

0% Exit to course

Module 1 · Complexity and how to think out loud Lesson 2 of 15

The pattern-first method

Learning objective

Interviews repeat patterns far more than they repeat problems. Naming the pattern is how a new question becomes a familiar one.

The concept

Interview questions are not 500 different problems; they are about a dozen patterns wearing different clothes. Two pointers, sliding window, hash map, binary search, recursion, breadth-first search, and a handful more. Recognising the pattern is most of the work — the code is then short.

The signals are in the question. "Sorted array" suggests two pointers or binary search. "Subarray" or "longest substring" suggests a window. "Have you seen this before", "count the frequency" or "find the pair" suggests a hash map. "Minimum number of steps in a grid" suggests BFS. Say which pattern you are considering and why — that sentence is worth more than typing.

Plain text
Signals in the question -> pattern:
  "sorted array", "pair sum"       -> two pointers / binary search
  "subarray", "longest substring"  -> sliding window
  "count frequency", "have I seen" -> hash map / set
  "minimum steps in a grid"        -> BFS

Name the pattern and WHY before you type a line.

Common mistakes

The mistake is starting to type while you are still deciding. Spend the first two minutes reading the example carefully and naming the pattern; the interviewer is scoring your approach, and a wrong approach written quickly scores nothing.

Worked example

"Find two numbers that add to a target" and "find a subarray with a given sum" are both the same two-pointer / hash-map family — recognising that is the whole skill.

Your practice task

Take ten problems you have solved and write the pattern name beside each one.

Do this before moving on. Reading a solution teaches the shape of it; typing it teaches you.

Key takeaway

Interview questions are not 500 different problems; they are about a dozen patterns wearing different clothes.

Create free account or sign in

Almost there

15 lessons left of 15

Finish every lesson to unlock the certificate. Each one ends in a practice task — do them and the final project brief writes itself.