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]

LeetCode 90: Subsets II, Derive Layer-Level Deduplication

Problem Requirement Input / Output Input: nums, with 1 <= nums.length <= 10 Value range: -10 <= nums[i] <= 10 nums may contain duplicates Output: return all unique subsets Ordering: the result order does not matter, but the same value sequence may appear only once Example Input: nums = [1,2,2] Output: [[],[1],[1,2],[1,2,2],[2],[2,2]] This tutorial starts with a correct but wasteful version, then derives sorting plus layer-level deduplication. Start From Duplicate Branches in [1,2,2] The smallest example that exposes the issue is: ...

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

Hot100: N-Queens Incremental Build Tutorial

51. N-Queens is best learned by watching the code grow one small step at a time. This tutorial keeps only the teaching path: tiny example, first DFS skeleton, first correct version, column-only optimization, then full diagonal-state optimization. Problem The n-queens puzzle asks us to place n queens on an n x n chessboard so that no two queens attack each other. Given an integer n, return all distinct solutions. Each solution is represented as a list of strings where: ...

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

Hot100: Palindrome Partitioning (Backtracking / Palindrome Table ACERS Guide)

Subtitle / Summary 131. Palindrome Partitioning is not hard because of recursion alone. The real challenge is separating two concerns clearly: where the next cut starts, and whether the current substring is a valid palindrome. Reading time: 15-18 min Tags: Hot100, backtracking, string, palindrome, DP SEO keywords: Palindrome Partitioning, backtracking, palindrome DP, string partition, LeetCode 131 Meta description: Learn LeetCode 131 by building the solution from scratch, using suffix-based DFS plus a precomputed palindrome table. A — Algorithm Problem Restatement Given a string s, partition it so that every substring in the partition is a palindrome. Return all possible palindrome partitionings of s. ...

April 19, 2026 · 15 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]