LeetCode 121: Best Time to Buy and Sell Stock With Greedy

Subtitle / Summary The greedy idea is not “buy low, sell high” as a slogan. The precise rule is: if today is the sell day, the best buy day must be the lowest price before today. Reading time: 8-10 min Tags: Hot100, greedy, array, stock SEO keywords: LeetCode 121, Best Time to Buy and Sell Stock, greedy, historical minimum price Meta description: A pressure-first Python guide to LeetCode 121 that derives brute force, historical minimum price, and the final one-pass greedy solution. Problem Requirement You are given an array prices, where prices[i] is the stock price on day i. ...

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

LeetCode 55: Jump Game With Farthest Reach Greedy

Subtitle / Summary Jump Game is not about guessing one path. It is about maintaining how far all reachable positions can cover. Reading time: 8-10 min Tags: Hot100, greedy, array, reachability SEO keywords: LeetCode 55, Jump Game, greedy, farthest reach, reachability Meta description: A pressure-first Python guide to LeetCode 55 that derives a reachable-array baseline and compresses it into the farthest reachable range. Problem Requirement You are given an integer array nums. ...

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

LeetCode 200: Number of Islands With Union-Find

Subtitle / Summary Do not start this problem by memorizing a Union-Find template. Start from the pressure: each land cell looks like one island at first, but adjacent land cells must collapse into one connected component. Reading time: 10-12 min Tags: Hot100, Union-Find, DSU, matrix, connected components SEO keywords: LeetCode 200, Number of Islands, Union-Find, DSU, connected components Meta description: A pressure-first Python guide to LeetCode 200 that derives land-only count, 2D-to-1D ids, Union-Find merges, and the final runnable solution. Problem Requirement You are given an m x n 2D character grid: ...

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

Union-Find Template: Derive find / union / count

Subtitle / Summary Union-Find is not a pair of function names to memorize first. It solves one concrete problem: decide whether two nodes already belong to the same set, and merge two sets when a connection appears. Reading time: 10-12 min Tags: Hot100, Union-Find, DSU, graph, connectivity SEO keywords: Union-Find, DSU, Disjoint Set Union, find, union, count, path compression Meta description: A Python Union-Find template guide that derives parent, find, union, count, connected, path compression, and connected component counting. A - Algorithm: Start From Set-Merging Pressure Tiny task: merge sets and answer connectivity Suppose we have 5 nodes: ...

June 30, 2026 · 10 min · map[name:Jeanphilo]

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 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]