Posts tagged

Recursion

Recursion for Interviews: Think Before You Code

A mental model for solving recursion interview problems without tracing every call. Introduces the 'leap of faith' — trust the recursive call to solve the smaller problem, then define only the base case, the reduction step, and the combine step. Applies the three-question framework to five real interview problems in Python: reversing a linked list, validating a BST with min/max bounds, generating subsets by include/exclude, counting climbing-stairs paths (with memoization), and generating balanced parentheses with backtracking. Covers the recursion-to-DP pipeline, Python's recursion limit, and the follow-up questions interviewers actually ask.

Backtracking Explained: N-Queens to Subsets

A complete guide to backtracking for coding interviews. Explains backtracking as constrained depth-first search over a decision tree, then introduces the universal choose/explore/unchoose template that solves nearly every backtracking interview problem. Works through four problem archetypes with full Python solutions: subsets (include/exclude decisions), permutations (ordering with a used-set), combination sum (reuse with pruning), and N-Queens (constraint satisfaction with column and diagonal tracking). Covers time complexity for each archetype, the classic mutable-list copy bug, and how to recognize a backtracking problem from its problem statement.