Coding interviews

A repeatable way to work any coding problem out loud, then the patterns most interview problems are built on, each with the signals that tell you to use it and the mistakes that cost points.

Essentials

Patterns

  • Two Pointers

    Recognize when sorted input, in-place edits or a linked list call for two pointers, then apply the opposite-ends, reader-writer and fast-slow shapes and say why each pointer move is safe.

    8 min read

  • Sliding Window

    Spot contiguous-range problems, run fixed and variable windows from one template, decide where to record the answer, and explain why the window breaks once values can be negative.

    8 min read

  • Binary Search

    Write one boundary-search template without off-by-one bugs, derive exact, first, last and count searches from it, and binary search on the answer and on rotated arrays.

    9 min read

  • Hash Maps and Prefix Sums

    Use maps for lookup, counting and grouping, build prefix sums for constant-time range queries, and count or find target-sum subarrays with a map of earlier prefixes, negatives included.

    8 min read

  • Stacks and Monotonic Stacks

    Solve nested-structure problems with a stack, find the next greater or smaller element for every position in one pass, and explain the push-once, pop-once reason it runs in linear time.

    8 min read

  • Heaps and Top K

    Recognize when a problem needs a heap, code its four shapes (top k, k-way merge, two heaps for a running median, scheduling by earliest end) and say when a plain sort or quickselect is the better answer.

    9 min read

  • Trees

    Decide whether information flows down a tree as arguments or up as return values, then write correct DFS, level-order BFS and BST solutions, including iterative traversal for trees too deep for recursion.

    9 min read

  • Graphs

    Model a problem as a graph and pick the right tool (BFS, DFS, topological sort, Dijkstra or union-find) while avoiding the visited-set and recursion-depth bugs that cost correctness points.

    9 min read

  • Backtracking: Searching Every Option Without Getting Lost

    Spot 'list every answer' problems, apply one choose, explore, unchoose template to subsets, permutations, combinations and constraint puzzles, prune early, and state the exponential cost honestly.

    9 min read

  • Dynamic Programming: From Recursion to a Table

    Recognize a dynamic programming problem, apply a five-step recipe (state, recurrence, base case, order, answer), move from memoization to a table and cut its space, and explain the solution out loud.

    9 min read

  • Intervals and Greedy: Sort First, Then Decide Once

    Merge, insert and count overlapping intervals with a sort-then-sweep template, justify a greedy rule with the exchange argument, and recognize when greedy fails and dynamic programming is needed.

    9 min read