LeetCode 78: Subsets, Derive the startIndex Backtracking Template

Problem Requirement Input / Output Input: nums, with 1 <= nums.length <= 10 Value range: -10 <= nums[i] <= 10 All elements in nums are distinct Output: return all possible subsets of nums Ordering: the result order does not matter, and subset element order is not the point Example Input: nums = [1,2,3] Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]] This tutorial builds one minimal Python solution. Start From the Search Tree for [1,2] The smallest branching example is: ...

May 3, 2026 · 6 min · map[name:Jeanphilo]

Hot100: Binary Tree Maximum Path Sum (Tree DP / Single-Side Gain ACERS Guide)

Subtitle / Summary The easiest way to get lost in LeetCode 124 is to make one recursive return value carry too much meaning. The stable design is to separate two roles: the recursion returns only the best single-side gain to the parent, while the full path through the current node is used to update the global maximum. Reading time: 12-15 min Tags: Hot100, binary tree, tree DP, DFS, postorder SEO keywords: Binary Tree Maximum Path Sum, tree DP, single-side gain, postorder, DFS, LeetCode 124 Meta description: Learn LeetCode 124 from the single-side gain invariant, global path update, and negative-branch pruning, with runnable multi-language implementations. A — Algorithm Problem Restatement A path in a binary tree is a sequence of nodes such that: ...

April 20, 2026 · 13 min · map[name:Jeanphilo]

Hot100: Diameter of Binary Tree (Tree DP / Height Return ACERS Guide)

Subtitle / Summary The most common confusion in LeetCode 543 is deciding what the recursive function should return. It should return height, not diameter. The diameter is updated globally at each node using leftHeight + rightHeight. Once that separation is clear, the problem becomes a clean introduction to tree DP. Reading time: 10-13 min Tags: Hot100, binary tree, tree DP, DFS, postorder SEO keywords: Diameter of Binary Tree, tree DP, height return, DFS, LeetCode 543 Meta description: Learn LeetCode 543 from the postorder height-return pattern, with step-by-step derivation, engineering analogies, and runnable multi-language solutions. A — Algorithm Problem Restatement Given the root root of a binary tree, return the diameter of the tree. ...

April 19, 2026 · 12 min · map[name:Jeanphilo]

Hot100: Lowest Common Ancestor of a Binary Tree (Postorder Return Semantics ACERS Guide)

Subtitle / Summary The real difficulty of LeetCode 236 is not memorizing an LCA template. It is defining what each recursive call should return. Once that return value becomes stable, the whole problem collapses into a short and very clean postorder recursion. Reading time: 11-14 min Tags: Hot100, binary tree, LCA, DFS, postorder SEO keywords: Lowest Common Ancestor of a Binary Tree, LCA, postorder, DFS, LeetCode 236 Meta description: Learn LeetCode 236 from the recursive return-value semantics, with step-by-step derivation, engineering mappings, and runnable multi-language implementations. A — Algorithm Problem Restatement Given a binary tree, find the lowest common ancestor (LCA) of two given nodes p and q. ...

April 19, 2026 · 14 min · map[name:Jeanphilo]

Hot100: Validate Binary Search Tree (Range Constraints / Inorder ACERS Guide)

Subtitle / Summary The hardest part of LeetCode 98 is usually not recursion itself. It is realizing that checking a node against only its parent is not enough. A valid BST is constrained by all of its ancestors, so the stable solution is to pass a valid range downward. This guide explains that idea from scratch, then connects it to the equivalent inorder-sorted view. Reading time: 11-13 min Tags: Hot100, binary tree, BST, DFS, inorder traversal SEO keywords: Validate Binary Search Tree, BST, range constraints, inorder traversal, DFS, LeetCode 98 Meta description: Learn LeetCode 98 from the core invariant low < val < high, with step-by-step derivation, engineering mappings, and runnable multi-language implementations. A — Algorithm Problem Restatement Given the root root of a binary tree, determine whether it is a valid binary search tree (BST). ...

April 19, 2026 · 12 min · map[name:Jeanphilo]

LeetCode 216: Combination Sum III (Backtracking / Fixed-Length Search ACERS Guide)

Subtitle / Summary 216. Combination Sum III is where backtracking adds one more important constraint: not only must the sum match, but the combination length must be exactly k. That turns the problem into a clean fixed-length combination search over the bounded range 1..9. Reading time: 12-15 min Tags: backtracking, fixed length, pruning, combination search SEO keywords: Combination Sum III, fixed-length backtracking, k numbers, pruning, LeetCode 216 Meta description: Build the stable solution for LeetCode 216 from scratch by understanding exact-length backtracking, sorted pruning, and the bounded candidate set 1..9. A — Algorithm Problem Restatement Find all valid combinations of k numbers that add up to n, subject to these rules: ...

April 17, 2026 · 12 min · map[name:Jeanphilo]

LeetCode 40: Combination Sum II (Backtracking / Same-Layer Dedup ACERS Guide)

Subtitle / Summary If 39. Combination Sum teaches “reuse is allowed”, then 40. Combination Sum II teaches the next real upgrade: duplicate values exist, each number may be used at most once, and de-duplication must happen at the correct tree level. Reading time: 14-16 min Tags: backtracking, dedup, pruning, combination search SEO keywords: Combination Sum II, backtracking, same-layer dedup, pruning, LeetCode 40 Meta description: Build the stable solution for LeetCode 40 from scratch by understanding sorted pruning, use-once recursion, and the same-layer duplicate skip rule. A — Algorithm Problem Restatement Given a collection of candidate numbers candidates and a target integer target, return all unique combinations where the chosen numbers sum to target. ...

April 17, 2026 · 14 min · map[name:Jeanphilo]

Hot100: Combination Sum (Backtracking / Pruning ACERS Guide)

Subtitle / Summary Combination Sum is the first Hot100 backtracking problem that really mixes three ideas at once: combination-style search, a running target, and safe pruning after sorting. The point is not to jump straight to the template, but to build it step by step from the problem itself. Reading time: 14-16 min Tags: Hot100, backtracking, combination sum, pruning SEO keywords: Combination Sum, backtracking, pruning, remain, DFS Meta description: Learn LeetCode 39 by building the solution from scratch, using path, remain, repeated candidate reuse, and sorted pruning. A — Algorithm Problem Restatement Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. ...

April 8, 2026 · 13 min · map[name:Jeanphilo]

Hot100: Permutations (used[] Backtracking ACERS Guide)

Subtitle / Summary If Subsets teaches the skeleton of combination-style backtracking, Permutations teaches the core of state-based backtracking: at each position, choose one unused element, continue until the path length reaches n, and only then collect the answer. Reading time: 10-12 min Tags: Hot100, backtracking, permutations, DFS SEO keywords: Permutations, backtracking, used array, DFS, LeetCode 46 Meta description: Learn the stable permutation backtracking template for LeetCode 46, with state recovery, engineering analogies, and runnable multi-language solutions. A — Algorithm Problem Restatement Given an array nums of distinct integers, return all possible permutations. The answer may be returned in any order. ...

April 3, 2026 · 10 min · map[name:Jeanphilo]

LeetCode 133: Clone Graph Hash Map + DFS/BFS ACERS Guide

Subtitle / Summary Clone Graph is not a traversal-only problem. The real challenge is preserving graph structure while avoiding duplicate copies in the presence of cycles. The stable solution is a traversal plus a hash map from original nodes to cloned nodes. Reading time: 12-15 min Tags: graph, dfs, bfs, hash map, deep copy SEO keywords: Clone Graph, graph deep copy, DFS, BFS, LeetCode 133 Meta description: Deep-copy an undirected graph with a node-to-node map, explaining why memoization is mandatory and how DFS/BFS versions work, with runnable code in six languages. Target Readers LeetCode learners practicing graph traversal and deep-copy patterns Engineers who duplicate object graphs, workflow graphs, or topology graphs Developers who want one reusable template for “clone with cycles” Background / Motivation Many “copy” problems are actually identity-preservation problems. ...

March 19, 2026 · 11 min · map[name:Jeanphilo]