Generate Parentheses: Counting Backtrack
Solve Generate Parentheses with counting-based backtracking. Clean invariant, walkthrough, complexity discussion, and interview tips.
84 posts · page 2 of 2
Solve Generate Parentheses with counting-based backtracking. Clean invariant, walkthrough, complexity discussion, and interview tips.
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.