Subsets: Every Prefix Is a Valid Answer
LeetCode 78 in Python. Emit the power set by recording at every node, recurse with i + 1, and copy the shared buffer before the next pop.
Series
A small, curated set of pattern write-ups — stacks, graphs, backtracking — not a dump of every prompt.
8 articles
LeetCode 78 in Python. Emit the power set by recording at every node, recurse with i + 1, and copy the shared buffer before the next pop.
LeetCode 39 in Python. Enumerate combinations that hit the target, reuse a candidate by staying at the same index, and skip generating permutations.
LeetCode 22 in Python. Build only valid strings with two counters, skip the generate-and-filter trap, and name the Catalan-shaped search tree interviewers expect.
LeetCode 739 in Python. The stack stores days still waiting for a warmer one, each index is pushed and popped once, and equal temperatures must not count.
LeetCode 20, Valid Parentheses, in Python. Why a stack is the only structure that works, the closing-bracket lookup trick, the three edge cases interviewers check, and the follow-ups that turn an Easy into a design question.
Given prerequisite pairs, decide if a course plan is possible. Kahn's algorithm in Python, the indegree trick, and the cycle case interviewers actually probe.
Design a least-recently-used cache in Python. Why a hash map alone is not enough, how OrderedDict encodes the recency list, and the capacity edge case.
Undirected graph deep copy with a hash map and BFS — the interview classic that checks whether you treat neighbors as pointers or as values.