Greedy

This section collects Hot100 greedy tutorials, focusing on which local state is enough, why it stays valid while scanning, and how that local choice proves the global answer. Recommended Reading Order LeetCode 121: Best Time to Buy and Sell Stock, derive one-transaction greedy from the historical minimum price LeetCode 55: Jump Game, use the farthest reachable range to decide reachability

July 3, 2026 · 1 min · map[name:Jeanphilo]

Union-Find

This section collects Hot100 Union-Find templates and problems, focusing on set representatives, path compression, merge conditions, connectivity checks, and connected component counting.

July 2, 2026 · 1 min · map[name:Jeanphilo]

Trie

This section collects Hot100 Trie tutorials, focusing on node fields, child traversal, end markers, and loop invariants.

June 25, 2026 · 1 min · map[name:Jeanphilo]

Binary Search

March 18, 2026 · 0 min · map[name:Jeanphilo]

LeetCode 684: Redundant Connection With Union-Find

Subtitle / Summary The key signal in this problem is not a component count. It is a failed union: if two endpoints are already connected, adding the current edge closes a cycle. Reading time: 8-10 min Tags: Union-Find, DSU, graph, tree, cycle detection SEO keywords: LeetCode 684, Redundant Connection, Union-Find, DSU, cycle detection Meta description: A pressure-first Python guide to LeetCode 684 that derives 1-indexed Union-Find, bool-returning union, ordered edge scanning, and final checks. Problem Requirement You are given an undirected graph. It started as a tree with n nodes labeled from 1 to n, then one extra edge was added. ...

July 2, 2026 · 7 min · map[name:Jeanphilo]

LeetCode 547: Number of Provinces, Turn an Adjacency Matrix into Connected Components

Problem Requirement You are given an n x n matrix isConnected, where there are n cities. If isConnected[i][j] == 1, city i and city j are directly connected. If two cities can reach each other through one or more directly connected cities, they belong to the same province. The problem asks you to return the total number of provinces. The easiest mistake is to think that the answer is the number of 1s in the matrix, or only the number of directly connected pairs. That is not what the problem asks. ...

May 29, 2026 · 16 min · map[name:Jeanphilo]

LeetCode 198: House Robber, Deriving 1D DP from Rob or Skip

Problem Input and Output Input: an integer array nums nums[i] is the money in the i-th house Adjacent houses cannot both be robbed Output: return the maximum amount of money that can be robbed Constraints: 1 <= nums.length <= 100, 0 <= nums[i] <= 400 Examples Input: nums = [1,2,3,1] Output: 4 Explanation: rob indices 0 and 2, for 1 + 3 = 4 Input: nums = [2,7,9,3,1] Output: 12 Explanation: rob indices 0, 2, and 4, for 2 + 9 + 1 = 12 This article uses Python only and derives 1D DP from the conflict between two choices. ...

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

LeetCode 70: Climbing Stairs, Deriving 1D DP from dp[i]

Problem Input and Output Input: an integer n Meaning: climb to the top of the n-step staircase Each move can climb 1 or 2 steps Output: return the number of distinct ways to reach the top Constraints: 1 <= n <= 45 Examples Input: n = 2 Output: 2 Explanation: 1+1, 2 Input: n = 3 Output: 3 Explanation: 1+1+1, 1+2, 2+1 This article uses Python only and derives the final solution step by step from the meaning of dp[i]. ...

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

LeetCode 746: Min Cost Climbing Stairs, Deriving DP from the Top Position

Problem Input and Output Input: an integer array cost cost[i] is the cost of stepping on stair i Each move can climb 1 or 2 steps You may start from index 0 or index 1 Output: return the minimum cost to reach the top Constraints: 2 <= cost.length <= 1000, 0 <= cost[i] <= 999 Examples Input: cost = [10,15,20] Output: 15 Explanation: start from index 1, pay 15, then reach the top directly Input: cost = [1,100,1,1,1,100,1,1,100,1] Output: 6 Start from the Top Position of [10,15,20] Look at the small example: ...

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

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: 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: Binary Tree Right Side View (Level Order Last-Node Rule ACERS Guide)

Subtitle / Summary LeetCode 199 is not really about visual imagination. It is about translating a viewpoint problem into a level problem. Once you realize that the right side view is simply the last node of each level, the problem becomes a standard breadth-first traversal. Reading time: 10-13 min Tags: Hot100, binary tree, BFS, level order, queue SEO keywords: Binary Tree Right Side View, BFS, level order, queue, right-first DFS, LeetCode 199 Meta description: Learn LeetCode 199 from the core equivalence “right side view = last node of each level”, with step-by-step derivation, engineering mappings, and runnable multi-language implementations. A — Algorithm Problem Restatement Given the root root of a binary tree, imagine standing on its right side and return the values of the nodes you can see from top to bottom. ...

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

Hot100: Construct Binary Tree from Preorder and Inorder Traversal (Indexed Divide-and-Conquer ACERS Guide)

Subtitle / Summary The key to LeetCode 105 is not memorizing that preorder and inorder can reconstruct a tree. It is understanding what each traversal contributes: preorder tells you the root, inorder tells you the left/right boundary. Once those roles are clear, the whole problem becomes a clean indexed divide-and-conquer. Reading time: 12-15 min Tags: Hot100, binary tree, divide and conquer, hash map, preorder SEO keywords: Construct Binary Tree from Preorder and Inorder Traversal, preorder, inorder, divide and conquer, hash map, LeetCode 105 Meta description: Learn LeetCode 105 from traversal roles, indexed recursion, and hash-map root lookup, with runnable multi-language implementations. A — Algorithm Problem Restatement Given the preorder traversal preorder and inorder traversal inorder of a binary tree, reconstruct the tree and return its root. ...

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