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 2379: Minimum Recolors to Get K Consecutive Black Blocks

LeetCode 2379: Minimum Recolors to Get K Consecutive Black Blocks Summary Given a string of ‘B’ and ‘W’, find the minimum recolors to make a substring of length k all black. Approach Use a sliding window of length k and count the number of whites in the window. The minimum whites across all windows is the answer. Complexity Time: O(n) Space: O(1) Python reference implementation def minimum_recolors(blocks, k): whites = sum(1 for c in blocks[:k] if c == 'W') ans = whites for i in range(k, len(blocks)): if blocks[i-k] == 'W': whites -= 1 if blocks[i] == 'W': whites += 1 ans = min(ans, whites) return ans

December 4, 2025 · 1 min · map[name:Jeanphilo]

LeetCode 2841: Maximum Sum of Almost Unique Subarray

LeetCode 2841: Maximum Sum of Almost Unique Subarray Summary Given an array, window size k, and threshold m, find the maximum sum of any length-k subarray that contains at least m distinct elements. Approach Use a sliding window with a frequency map, track window sum and number of distinct values. Complexity Time: O(n) Space: O(n) for frequency map Python reference implementation def max_sum_almost_unique(nums, m, k): from collections import defaultdict count = defaultdict(int) distinct = 0 window_sum = 0 ans = 0 for i, x in enumerate(nums): window_sum += x if count[x] == 0: distinct += 1 count[x] += 1 if i >= k: y = nums[i - k] window_sum -= y count[y] -= 1 if count[y] == 0: distinct -= 1 if i >= k - 1 and distinct >= m: ans = max(ans, window_sum) return ans

December 4, 2025 · 1 min · map[name:Jeanphilo]