LeetCode 208: Implement Trie (Prefix Tree) in Python

Subtitle / Summary LeetCode 208 is the fixed-interface version of the Trie template. We will derive the node fields and lookup invariant first, then fit them into Trie(), insert, search, and startsWith. Reading time: 10-12 min Tags: Hot100, Trie, prefix tree, LeetCode 208 SEO keywords: LeetCode 208, Implement Trie, Prefix Tree, Python Trie, startsWith, is_end Meta description: A pressure-first Python guide to LeetCode 208 covering Trie nodes, children, is_end, insert, search, startsWith, and submission checks. A - Algorithm Problem setup: design a prefix-tree word index The task is to design a mutable word index. The index starts empty, then receives words one by one, and must answer two kinds of lookup: ...

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

Trie Template Guide: Node Fields, Child Traversal, and Loop Invariants

Subtitle / Summary Build a Trie from a small word-index task instead of memorizing the final class. The key model is: a node represents a prefix reached by a path, and is_end decides whether that prefix is also a complete word. Reading time: 10-12 min Tags: Hot100, Trie, prefix tree, string SEO keywords: Trie template, Python Trie, prefix tree, children, is_end, LeetCode 208 Meta description: A minimal Python Trie template that derives node fields, child traversal, end markers, prefix search, and insert/search loop invariants. A - Algorithm: Start From A Small Task Tiny task: build a word index for lookup and autocomplete Suppose we are building a small word index for a search box. After adding: ...

June 25, 2026 · 10 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]