Posts tagged

Problem Solving

Binary Search: Not Just for Sorted Arrays

Reframes binary search as a general search-space reduction technique rather than a sorted-array lookup trick. Covers the classic template and the two bugs that break it, then extends the idea to 'search on the answer' problems like Koko Eating Bananas and Split Array Largest Sum, and to rotated sorted arrays. Works through six real interview problems with Python solutions, explains how to recognize a hidden binary search from monotonicity, and shows why the same 15-line template solves problems that look nothing like array lookup.

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.