Binary Search

August 13, 2026 · 0 min · map[name:Jeanphilo]

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 LeetCode 45: Jump Game II, upgrade reachability into minimum jump layers LeetCode 435: Non-overlapping Intervals, turn minimum removals into maximum kept intervals LeetCode 452: Minimum Number of Arrows, derive interval greedy from shared intersections

July 8, 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]

LeetCode 139: Word Break, Starting from Prefix Reachability

Problem Input and Output Input: a string s and a list of strings wordDict Every element in wordDict is an available word, and the same word may be reused Output: return True if s can be split into one or more dictionary words; otherwise, return False The split must cover the entire string without skipping or reordering characters Examples Input: s = "leetcode", wordDict = ["leet", "code"] Output: True Explanation: "leetcode" can be split into "leet" + "code" Input: s = "applepenapple", wordDict = ["apple", "pen"] Output: True Explanation: "apple" + "pen" + "apple"; the same word may be reused Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"] Output: False Explanation: some prefixes can be formed, but the split cannot cover the entire string Constraints 1 <= s.length <= 300 1 <= wordDict.length <= 1000 1 <= wordDict[i].length <= 20 s and wordDict[i] contain only lowercase English letters All strings in wordDict are unique Step 1: Make the Completed Prefix Visible Start with one concrete question. For s = "leetcode", before deciding whether the whole string can be split, can we record how much of it has already been completed? ...

September 22, 2026 · 12 min · map[name:Jeanphilo]

LeetCode 213: House Robber II, Splitting the Circle into Two Linear Problems

Problem Input and Output Input: an integer array nums, where nums[i] is the money in the i-th house. The houses form a circle. Adjacent houses cannot both be robbed, so houses 0 and n - 1 cannot both be robbed either. Output: the maximum amount of money that can be robbed without triggering the alarm. Constraints: 1 <= nums.length <= 100, 0 <= nums[i] <= 1000. Examples Input: nums = [2,3,2] Output: 3 Explanation: Houses 0 and 2 are adjacent around the circle, so they cannot both be robbed; rob the house containing 3. Input: nums = [1,2,3,1] Output: 4 Explanation: We can rob indices 0 and 2, or indices 1 and 3. Input: nums = [1,2,3] Output: 3 This tutorial uses Python only and starts with the smallest first-last conflict. ...

September 22, 2026 · 11 min · map[name:Jeanphilo]

LeetCode 322: Coin Change, Deriving Unbounded Knapsack DP from Smaller Amounts

Problem Requirements You are given an integer array coins, where coins[i] is a coin denomination, and a non-negative integer amount. The goal is to make a total exactly equal to amount. You may use each denomination any number of times. Return the minimum number of coins needed to make amount. If the amount cannot be made, return -1. If amount = 0, no coins are needed, so the answer is 0. The constraints are 1 <= coins.length <= 12, 1 <= coins[i] <= 2^31 - 1, and 0 <= amount <= 10^4. All coin denominations are distinct. ...

September 22, 2026 · 13 min · map[name:Jeanphilo]

LeetCode 300: Longest Increasing Subsequence, Deriving Sequence DP from Ending at i

Problem Input and Output Input: an integer array nums Output: return the length of the longest strictly increasing subsequence in nums A subsequence preserves the relative order of the original array, but it does not need to be contiguous, so elements may be skipped If the selected indices are i_1 < i_2 < ... < i_k, they must also satisfy nums[i_1] < nums[i_2] < ... < nums[i_k] The subsequence is non-empty, so at least one element must be selected Constraints: 1 <= nums.length <= 2500, -10^4 <= nums[i] <= 10^4 Examples Input: nums = [10,9,2,5,3,7,101,18] Output: 4 Explanation: [2,5,7,101] is a strictly increasing subsequence of length 4; its elements do not need to be contiguous in the original array. Input: nums = [0,1,0,3,2,3] Output: 4 Explanation: [0,1,2,3] has length 4; [0,1,3] is also valid, but shorter. This article uses Python only. We start with the local question “how long can a subsequence ending at each position be?” and gradually turn it into a runnable solution. ...

September 22, 2026 · 12 min · map[name:Jeanphilo]

LeetCode 416: Partition Equal Subset Sum, from the Half-Sum Target to Backward 0/1 Knapsack

Problem Requirements Given an array nums containing only positive integers, determine whether all its elements can be split into two subsets whose sums are equal. Input and Output Input: an integer array nums Output: return True if the array can be split equally; otherwise, return False Every element must belong to exactly one of the two subsets. No element may be discarded or used twice Examples Input: nums = [1,5,11,5] Output: True Explanation: [1,5,5] and [11] both have a sum of 11 Input: nums = [1,2,3,5] Output: False Explanation: the total is 11, and an odd total cannot be split equally Input: nums = [1,1] Output: True Explanation: put one 1 in each subset Constraints According to the LeetCode 416 statement: ...

September 22, 2026 · 14 min · map[name:Jeanphilo]

LeetCode 155: Min Stack, Keeping the Minimum in Sync With Stack State

Problem Requirement Design a stack named MinStack that supports these operations: MinStack(): initialize the stack. push(value): push value onto the stack. pop(): remove the top element. top(): return the top element. getMin(): return the minimum element in the stack. Every operation must run in O(1) time. pop, top, and getMin are called only when the stack is non-empty, so no additional empty-stack return value is needed. Example Operations: ["MinStack", "push", "push", "push", "getMin", "pop", "top", "getMin"] Arguments: [[], [-2], [0], [-3], [], [], [], []] Output: [null, null, null, null, -3, null, 0, -2] The sequence corresponds to: ...

August 21, 2026 · 7 min · map[name:Jeanphilo]

LeetCode 20: Valid Parentheses, Why Equal Counts Are Not Enough

Problem Requirement You are given a string s containing only these six characters: ( ) { } [ ] Determine whether the string is valid. A valid string must satisfy all three conditions: Every opening bracket is closed by the same type of closing bracket. Opening brackets are closed in the correct order. Every closing bracket has a corresponding opening bracket of the same type. Return True when all conditions hold; otherwise, return False. ...

August 21, 2026 · 7 min · map[name:Jeanphilo]

LeetCode 394: Decode String by Saving and Restoring Nested Context

Problem Requirement Given an encoded string s, return its decoded string. The encoding rule is: k[encoded_string] The encoded_string inside the brackets is repeated exactly k times, where k is a positive integer. Encodings may be nested or adjacent to ordinary lowercase letters. The problem guarantees that: The input is always valid, with matching brackets and no extra spaces. Original text contains no digits; digits only represent repeat counts. Inputs such as 3a or 2[4] do not occur. The decoded string length does not exceed 10^5. Examples Input Output "3[a]2[bc]" "aaabcbc" "3[a2[c]]" "accaccacc" "2[abc]3[cd]ef" "abcabccdcdcdef" Constraints 1 <= s.length <= 30 s contains only lowercase English letters, digits, and [] Every repeat count is in [1, 300] LeetCode provides this method signature: ...

August 21, 2026 · 10 min · map[name:Jeanphilo]

LeetCode 503: Where Does the Right Side End in a Circular Array?

Problem Requirement You are given a circular integer array nums. Return an array answer. For every index i: answer[i] = the first value strictly greater than nums[i] when moving right If one full trip around the array finds no greater value, answer[i] = -1. “Circular” means that moving past the final position continues from index 0. An index cannot travel one full circle and use itself as its own answer. ...

July 20, 2026 · 9 min · map[name:Jeanphilo]

LeetCode 84: Which Bar Limits a Contiguous Rectangle?

Problem Requirement You are given a non-negative integer array heights. Each heights[i] is the height of a bar with width 1, and all bars are adjacent. Return the area of the largest rectangle that can be formed in the histogram. A legal rectangle covers a contiguous interval of bars. Its width is the number of bars in that interval, and its height cannot exceed the shortest bar in the interval. ...

July 20, 2026 · 10 min · map[name:Jeanphilo]