House Robber: The Pick-or-Skip DP Template
Solve House Robber with the pick-or-skip DP recurrence, then optimize to O(1) space. Includes interview script and related variants.
1745 posts · page 31 of 37
Solve House Robber with the pick-or-skip DP recurrence, then optimize to O(1) space. Includes interview script and related variants.
Solve Invert Binary Tree with a four-line recursive swap and an iterative BFS alternative, including complexity and interview talking points.
The inorder traversal trick, the iterative early-exit version, and the follow-up that haunts FAANG interviews.
Solve Letter Combinations of a Phone Number with backtracking. Mapping setup, recursive enumeration, complexity, and interview walkthrough.
Solve Longest Consecutive Sequence in O(n) using a hash set and a start-of-run check. Walkthrough, edge cases, and interview script.
Longest Increasing Subsequence in detail — the O(n^2) DP, the O(n log n) patience-sorting trick with binary search, and when each one matters.
Walk through the Longest Palindromic Substring problem using the expand-around-center technique. Compare brute force, DP, and the optimal approach with examples.
Design LRU Cache with a hash map and a doubly linked list to get O(1) get and put, with a clean implementation and interview tips.
Solve Longest Substring Without Repeating Characters using a sliding window with a hash map. We go from brute force to a clean O(n) sweep.
Why BST ordering collapses LCA into a one-line traversal, and the iterative version that needs zero extra space.
Compute tree depth with a three-line recursive DFS and an iterative BFS alternative, with complexity analysis and interview tips.
A clear walkthrough of Maximum Subarray. We build Kadane's algorithm from first principles and contrast it with the divide and conquer approach.
Design a stack that supports push, pop, top, and getMin in constant time. Walkthrough of the two-stack and pair-stack solutions with edge cases and interview tips.
Solve Number of Islands with grid DFS and BFS, including a union-find variant, edge-case handling, and clear interview talking points.
Solve Merge Two Sorted Lists with the dummy-head pointer pattern, plus a recursive variant, edge cases, and interview explanation tips.
Why reverse traversal beats per-cell flood fill, and how the intersection of two reach sets gives the answer.
The DFS-with-decrement trick, why the leaf condition is the whole problem, and the variants that build on it.
Solve Permutations with backtracking and a used array. Compare swap-in-place vs used-array, walkthrough, complexity, and interview tips.
Solve Product of Array Except Self in O(n) without division using prefix and suffix passes. Clean walkthrough plus interview script.
Walk through Reverse Linked List with iterative pointer flipping and a clean recursive solution, plus complexity and interview talking points.
Rotate an n by n matrix 90 degrees in place by transposing and reversing each row. Walkthrough, edge cases, complexity, and interview script.
Solve Search in Rotated Sorted Array in O(log n) with modified binary search. Pivot detection, half-decision logic, and interview talking points.
The preorder-with-nulls encoding, the iterator-driven decoder, and why level-order is a worse choice than it looks.
Solve Sliding Window Maximum in O(n) using a monotonic deque. Step-by-step walkthrough, interview script, and complexity analysis.
Solve Spiral Matrix with the four-boundary walk pattern. Clean implementation, edge cases for rectangles, complexity, and interview tips.
Generate all subsets of an array using backtracking and iterative bit-mask approaches. Includes complexity analysis and interview script.
Solve Top K Frequent Elements with both a min-heap and a bucket sort approach. Trade-offs, complexity, and interview-ready walkthrough.
A complete walkthrough of the Two Sum problem. We move from the obvious nested loop to a single-pass hash map and dissect why it works.
Solve Trapping Rain Water in linear time and constant space using the two-pointer technique. Brute force, optimal walkthrough, and interview talk track.
Unique Paths in two ways — the O(m * n) grid DP that interviewers expect and the binomial-coefficient closed form that surprises them.
A complete walkthrough of the Valid Anagram problem. Compare the sorting approach with the optimal hash map counting solution and learn how to explain it in interviews.
A clean walkthrough of Valid Parentheses with the optimal stack solution. Covers edge cases, complexity, and how to explain the approach in interviews.
The seductive wrong answer, the correct min/max bounds approach, and how to defend it in an interview.
Solve Word Break with bottom-up dynamic programming. Includes brute force, edge cases, complexity analysis, and an interview script.
The wildcard-pattern adjacency trick, why BFS is mandatory, and the bidirectional speedup.
The essential math toolkit for interviews: Euclidean GCD, sieve of Eratosthenes, modular exponentiation, modular inverses, and common pitfalls.
Learn segment trees for fast range sum, min, and max queries with point updates, including a clean iterative Python implementation.
Compare Kahn's BFS-based topological sort with DFS-based postorder, with Python implementations, complexity, and cycle detection.
A practical introduction to tries: node structure, insert, search, prefix queries, memory tradeoffs, and classic interview problems like word search.
Learn the union-find data structure with union by rank and path compression, why it runs in near-O(1) amortized, and how it powers Kruskal and islands.
A practical guide to Go error handling: the error interface, sentinel values, custom types, wrapping with fmt.Errorf %w, and errors.Is and errors.As.
Learn Go concurrency from the ground up: launching goroutines, communicating via channels, using select, range, and building a worker pool pattern.
A practical tour of Go packages and modules: go mod init, imports, internal packages, semantic versioning, and the replace directive for local development.
A clear guide to Go structs and methods: literal forms, defining methods, choosing value vs pointer receivers, and using embedding for composition.
Design Java classes that hold state and behavior cleanly. Constructors, encapsulation, static vs instance, records, and the equals plus hashCode contract.
Pick the right Java collection by performance and semantics. ArrayList vs LinkedList, HashMap vs TreeMap, immutability, and iteration without surprises.
Every branching and looping construct in modern Java, including switch expressions and pattern matching, with examples that mirror real code.
Use extends, super, and method overriding without painting yourself into a corner. When to inherit, when to compose, and how sealed types help.