Resources / Coding
Free to readCoding⏱ 4 min read

Coding interview patterns — the 150-problem plan

The 14 patterns behind most coding interview questions, the order to learn them, and a 6-week plan to finish 150 problems.

Why patterns, not random problems

Most interview questions are the same 14 ideas in new clothes. If you learn the idea once and practise 8–12 problems on it, you can solve new ones you have never seen. Solving 500 random problems without patterns is slower and you forget them.

The 14 patterns (learn in this order)

📖 Hash table (dictionary / map)

Definition: A hash table is a data structure that stores key–value pairs and uses a hash function to compute an index into an array of buckets, giving average O(1) insert, lookup and delete.

How it works: The hash function maps a key to a bucket; collisions (two keys in one bucket) are handled by chaining or open addressing. Performance degrades to O(n) in the worst case, so good hash functions and resizing matter.

Example: Python dict, Java HashMap: checking "[email protected]" in seen is instant.

📖 Dynamic programming

Definition: Dynamic programming solves a problem by breaking it into overlapping subproblems, solving each subproblem once and storing its result.

How it works: It applies when a problem has optimal substructure and overlapping subproblems. Memoisation = top-down recursion with a cache; tabulation = bottom-up filling of a table. Define the state, the transition (recurrence) and the base cases.

Example: Ways to climb n stairs = ways(n−1) + ways(n−2), computed once per n.

🧒 In simple words

#PatternWhen to think of itStarter problem
1Arrays & hashing"find duplicates", "count", "pairs that sum to"Two Sum
2Two pointerssorted array, palindrome, pairs from both endsValid Palindrome
3Sliding window"longest / shortest substring or subarray with…"Longest substring without repeating characters
4Stackbrackets, "next greater element", undoValid Parentheses
5Binary searchsorted data, "minimum value that works"Search in rotated sorted array
6Linked listreverse, merge, cycleReverse Linked List
7Trees (DFS/BFS)anything with a root and childrenMaximum depth of binary tree
8Heap / priority queue"top K", "K closest", merge K listsKth largest element
9Backtracking"all combinations / permutations / subsets"Subsets
10Graphsgrids, islands, prerequisitesNumber of islands
11Dynamic programming 1-D"number of ways", "max profit", choices in a lineClimbing stairs
12Dynamic programming 2-Dtwo strings, gridsLongest common subsequence
13Greedy & intervalsmeetings, merging rangesMerge intervals
14Bit manipulation & mathsXOR tricks, powers of twoSingle number

How to practise one problem (the 25-minute rule)

  1. Read the problem twice. Write 2 small examples by hand.
  2. Say the brute-force idea out loud, with its time complexity.
  3. Ask: which pattern does this look like? Improve the idea.
  4. Code it. Run your examples. Then try an empty input and a single element.
  5. Stuck for 25 minutes? Read the solution, close it, and write it again yourself tomorrow.
💡 Tip

Keep a "mistakes notebook": one line per problem — what the trick was. Re-read it every Sunday.

6-week plan (about 25 problems a week)

WeekPatternsTarget
1Arrays & hashing, two pointers25 easy/medium
2Sliding window, stack, binary search25
3Linked list, trees25
4Heap, backtracking, graphs25
5Dynamic programming25
6Greedy, intervals, bits + 10 mixed mocks25

Big-O in one table

📖 Big-O notation

Definition: Big-O notation describes an upper bound on how an algorithm's running time or memory grows as the input size n grows, ignoring constants and lower-order terms.

How it works: We usually quote the worst case. O(1) constant, O(log n) logarithmic, O(n) linear, O(n log n) linearithmic, O(n²) quadratic, O(2ⁿ) exponential. Space complexity uses the same notation for memory.

Example: Scanning a list once is O(n); two nested loops over it are O(n²).

🧒 In simple words

ComplexityMeansExample
O(1)instantread arr[5]
O(log n)halves every stepbinary search
O(n)look at each item oncefind the max
O(n log n)sortingmerge sort
O(n²)every pairtwo nested loops

What interviewers look for

  • You talk while you think — silence is the biggest mistake.
  • You start with a simple working idea, then improve it.
  • Clean variable names and you test your own code.
  • You know the time and space complexity of your answer.

Further reading

When you finish this plan, practise on:

🔥Join the free 30-Day Placement ChallengeOne resource and one task a day — from resume to offer.