<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>LeetCode on Jeanphilo Blog</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/</link><description>Recent content in LeetCode on Jeanphilo Blog</description><generator>Hugo -- 0.168.0</generator><language>en-us</language><lastBuildDate>Sat, 10 Oct 2026 10:00:00 +0800</lastBuildDate><atom:link href="https://jeanphilogong.github.io/jeanblog/alg/leetcode/index.xml" rel="self" type="application/rss+xml"/><item><title>LeetCode 1282: Group the People, from Capacity Buckets to Emitting Full Groups</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/1282-group-the-people-given-the-group-size-they-belong-to/</link><pubDate>Sat, 10 Oct 2026 10:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/1282-group-the-people-given-the-group-size-they-belong-to/</guid><description>Distinguish person IDs from group sizes, collect and split capacity buckets, then build a one-pass Python solution that emits full groups without mutating saved results.</description></item><item><title>LeetCode 49: Group Anagrams, from Scanning Groups to Building a Grouping Key</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/49-group-anagrams/</link><pubDate>Sat, 10 Oct 2026 10:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/49-group-anagrams/</guid><description>Build a Python solution one step at a time: compare two anagrams, scan group representatives, then derive sorted-string and character-count keys to understand why hash-table grouping works.</description></item><item><title>LeetCode 609: Find Duplicate File in System, from Parsing Records to Grouping by Content</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/609-find-duplicate-file-in-system/</link><pubDate>Sat, 10 Oct 2026 10:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/609-find-duplicate-file-in-system/</guid><description>Solve LeetCode 609 step by step: parse directory descriptions, build a correct pairwise baseline, group by content, and account for path construction and real-filesystem limitations.</description></item><item><title>LeetCode 152: Maximum Product Subarray, Deriving Two DP States from a Negative Counterexample</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/152-maximum-product-subarray/</link><pubDate>Thu, 08 Oct 2026 00:00:00 +0000</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/152-maximum-product-subarray/</guid><description>Start by enumerating nonempty contiguous ranges, then use a negative counterexample to derive maximum and minimum product states and a constant-space Python solution.</description></item><item><title>LeetCode 279: Perfect Squares, Deriving Dynamic Programming from Remaining Sums</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/279-perfect-squares/</link><pubDate>Thu, 08 Oct 2026 00:00:00 +0000</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/279-perfect-squares/</guid><description>Start with a failed largest-square choice, then build recursion, memoization, and iterative dynamic programming to minimize the number of perfect squares.</description></item><item><title>LeetCode 139: Word Break, Starting from Prefix Reachability</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/139-word-break/</link><pubDate>Tue, 22 Sep 2026 12:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/139-word-break/</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;h3 id="input-and-output"&gt;Input and Output&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Input: a string &lt;code&gt;s&lt;/code&gt; and a list of strings &lt;code&gt;wordDict&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Every element in &lt;code&gt;wordDict&lt;/code&gt; is an available word, and the same word may be reused&lt;/li&gt;
&lt;li&gt;Output: return &lt;code&gt;True&lt;/code&gt; if &lt;code&gt;s&lt;/code&gt; can be split into one or more dictionary words; otherwise, return &lt;code&gt;False&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The split must cover the entire string without skipping or reordering characters&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="examples"&gt;Examples&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: s = &amp;#34;leetcode&amp;#34;, wordDict = [&amp;#34;leet&amp;#34;, &amp;#34;code&amp;#34;]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: True
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: &amp;#34;leetcode&amp;#34; can be split into &amp;#34;leet&amp;#34; + &amp;#34;code&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: s = &amp;#34;applepenapple&amp;#34;, wordDict = [&amp;#34;apple&amp;#34;, &amp;#34;pen&amp;#34;]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: True
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: &amp;#34;apple&amp;#34; + &amp;#34;pen&amp;#34; + &amp;#34;apple&amp;#34;; the same word may be reused
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: s = &amp;#34;catsandog&amp;#34;, wordDict = [&amp;#34;cats&amp;#34;, &amp;#34;dog&amp;#34;, &amp;#34;sand&amp;#34;, &amp;#34;and&amp;#34;, &amp;#34;cat&amp;#34;]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: False
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: some prefixes can be formed, but the split cannot cover the entire string
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="constraints"&gt;Constraints&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= s.length &amp;lt;= 300&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= wordDict.length &amp;lt;= 1000&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;1 &amp;lt;= wordDict[i].length &amp;lt;= 20&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;s&lt;/code&gt; and &lt;code&gt;wordDict[i]&lt;/code&gt; contain only lowercase English letters&lt;/li&gt;
&lt;li&gt;All strings in &lt;code&gt;wordDict&lt;/code&gt; are unique&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="step-1-make-the-completed-prefix-visible"&gt;Step 1: Make the Completed Prefix Visible&lt;/h2&gt;
&lt;p&gt;Start with one concrete question. For &lt;code&gt;s = &amp;quot;leetcode&amp;quot;&lt;/code&gt;, before deciding whether the whole string can be split, can we record how much of it has already been completed?&lt;/p&gt;</description></item><item><title>LeetCode 213: House Robber II, Splitting the Circle into Two Linear Problems</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/213-house-robber-ii/</link><pubDate>Tue, 22 Sep 2026 10:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/213-house-robber-ii/</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;h3 id="input-and-output"&gt;Input and Output&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Input: an integer array &lt;code&gt;nums&lt;/code&gt;, where &lt;code&gt;nums[i]&lt;/code&gt; is the money in the &lt;code&gt;i&lt;/code&gt;-th house.&lt;/li&gt;
&lt;li&gt;The houses form a circle. Adjacent houses cannot both be robbed, so houses &lt;code&gt;0&lt;/code&gt; and &lt;code&gt;n - 1&lt;/code&gt; cannot both be robbed either.&lt;/li&gt;
&lt;li&gt;Output: the maximum amount of money that can be robbed without triggering the alarm.&lt;/li&gt;
&lt;li&gt;Constraints: &lt;code&gt;1 &amp;lt;= nums.length &amp;lt;= 100&lt;/code&gt;, &lt;code&gt;0 &amp;lt;= nums[i] &amp;lt;= 1000&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="examples"&gt;Examples&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: nums = [2,3,2]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 3
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: Houses 0 and 2 are adjacent around the circle, so they cannot both be robbed; rob the house containing 3.
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: nums = [1,2,3,1]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 4
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: We can rob indices 0 and 2, or indices 1 and 3.
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: nums = [1,2,3]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 3
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This tutorial uses Python only and starts with the smallest first-last conflict.&lt;/p&gt;</description></item><item><title>LeetCode 322: Coin Change, Deriving Unbounded Knapsack DP from Smaller Amounts</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/322-coin-change/</link><pubDate>Tue, 22 Sep 2026 00:00:00 +0000</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/322-coin-change/</guid><description>Start from a greedy failure and smaller-amount subproblems, then build an unbounded knapsack DP that finds the minimum number of coins.</description></item><item><title>LeetCode 300: Longest Increasing Subsequence, Deriving Sequence DP from Ending at i</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/300-longest-increasing-subsequence/</link><pubDate>Tue, 22 Sep 2026 00:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/300-longest-increasing-subsequence/</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;h3 id="input-and-output"&gt;Input and Output&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Input: an integer array &lt;code&gt;nums&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Output: return the length of the longest strictly increasing subsequence in &lt;code&gt;nums&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;A subsequence preserves the relative order of the original array, but it does not need to be contiguous, so elements may be skipped&lt;/li&gt;
&lt;li&gt;If the selected indices are &lt;code&gt;i_1 &amp;lt; i_2 &amp;lt; ... &amp;lt; i_k&lt;/code&gt;, they must also satisfy &lt;code&gt;nums[i_1] &amp;lt; nums[i_2] &amp;lt; ... &amp;lt; nums[i_k]&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;The subsequence is non-empty, so at least one element must be selected&lt;/li&gt;
&lt;li&gt;Constraints: &lt;code&gt;1 &amp;lt;= nums.length &amp;lt;= 2500&lt;/code&gt;, &lt;code&gt;-10^4 &amp;lt;= nums[i] &amp;lt;= 10^4&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="examples"&gt;Examples&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: nums = [10,9,2,5,3,7,101,18]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 4
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;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.
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: nums = [0,1,0,3,2,3]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 4
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: [0,1,2,3] has length 4; [0,1,3] is also valid, but shorter.
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This article uses Python only. We start with the local question &amp;ldquo;how long can a subsequence ending at each position be?&amp;rdquo; and gradually turn it into a runnable solution.&lt;/p&gt;</description></item><item><title>LeetCode 416: Partition Equal Subset Sum, from the Half-Sum Target to Backward 0/1 Knapsack</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/416-partition-equal-subset-sum/</link><pubDate>Tue, 22 Sep 2026 00:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/416-partition-equal-subset-sum/</guid><description>Start from the constraints of Partition Equal Subset Sum, build the 0/1 knapsack state step by step, and see why one-dimensional compression requires backward iteration.</description></item><item><title>LeetCode 155: Min Stack, Keeping the Minimum in Sync With Stack State</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/155-min-stack/</link><pubDate>Fri, 21 Aug 2026 00:00:00 +0000</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/155-min-stack/</guid><description>Start from restoring the previous minimum after pop, build a correct scan baseline, and derive an O(1) Min Stack with synchronized prefix minima.</description></item><item><title>LeetCode 20: Valid Parentheses, Why Equal Counts Are Not Enough</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/20-valid-parentheses/</link><pubDate>Fri, 21 Aug 2026 00:00:00 +0000</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/20-valid-parentheses/</guid><description>Start from the counterexample ([)], separate equal bracket counts from correct types and closing order, and derive an O(n) stack solution.</description></item><item><title>LeetCode 394: Decode String by Saving and Restoring Nested Context</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/394-decode-string/</link><pubDate>Fri, 21 Aug 2026 00:00:00 +0000</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/394-decode-string/</guid><description>Start from the context lost by nested encoding, build a correct recursive parser, and make its saved frames explicit with a stack.</description></item><item><title>LeetCode 503: Where Does the Right Side End in a Circular Array?</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/503-next-greater-element-ii/</link><pubDate>Mon, 20 Jul 2026 00:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/503-next-greater-element-ii/</guid><description>Start from the exact circular next-greater query, build a verifiable scan, then derive a linear monotonic-stack solution that pushes each original index once.</description></item><item><title>LeetCode 84: Which Bar Limits a Contiguous Rectangle?</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/84-largest-rectangle-in-histogram/</link><pubDate>Mon, 20 Jul 2026 00:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/84-largest-rectangle-in-histogram/</guid><description>Start from the shortest bar in a contiguous interval, build an interval baseline, then derive a linear monotonic-stack solution that settles maximal widths.</description></item><item><title>LeetCode 136: Single Number Without Growing Extra Storage</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/136-single-number/</link><pubDate>Wed, 15 Jul 2026 00:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/136-single-number/</guid><description>Start from a set-based pairing baseline, derive XOR cancellation, and solve LeetCode 136 in O(n) time with O(1) extra space.</description></item><item><title>LeetCode 191: Number of 1 Bits and How to Skip Irrelevant Zeros</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/191-number-of-1-bits/</link><pubDate>Wed, 15 Jul 2026 00:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/191-number-of-1-bits/</guid><description>Start from a right-shift baseline, derive how n &amp;amp; (n - 1) clears one lowest set bit, and prove LeetCode 191 with a loop invariant.</description></item><item><title>LeetCode 338: Counting Bits by Reusing Smaller Results</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/338-counting-bits/</link><pubDate>Wed, 15 Jul 2026 00:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/338-counting-bits/</guid><description>Start by counting every value in 0..n independently, then derive answer[i] = answer[i &amp;amp; (i - 1)] + 1 for an O(n) solution.</description></item><item><title>LeetCode 739: Daily Temperatures and the First Warmer Day to the Right</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/739-daily-temperatures/</link><pubDate>Wed, 15 Jul 2026 00:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/739-daily-temperatures/</guid><description>Start from an O(n^2) right-scan baseline, derive a monotonic stack of unresolved indices, and solve LeetCode 739 in O(n) time.</description></item><item><title>LeetCode 684: Redundant Connection With Union-Find</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/union-find/684-redundant-connection/</link><pubDate>Thu, 02 Jul 2026 00:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/union-find/684-redundant-connection/</guid><description>Solve LeetCode 684 Redundant Connection in Python by deriving the already-connected edge pressure, 1-indexed parent array, bool-returning union, and ordered edge scan.</description></item><item><title>LeetCode 547: Number of Provinces, Turn an Adjacency Matrix into Connected Components</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/547-number-of-provinces/</link><pubDate>Fri, 29 May 2026 00:00:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/547-number-of-provinces/</guid><description>Turn LeetCode 547 Number of Provinces from direct connections in an adjacency matrix into connected component counting, then derive DFS, BFS, and Union Find solutions step by step.</description></item><item><title>LeetCode 198: House Robber, Deriving 1D DP from Rob or Skip</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/198-house-robber/</link><pubDate>Sun, 03 May 2026 14:33:39 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/198-house-robber/</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;h3 id="input-and-output"&gt;Input and Output&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Input: an integer array &lt;code&gt;nums&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;nums[i]&lt;/code&gt; is the money in the &lt;code&gt;i&lt;/code&gt;-th house&lt;/li&gt;
&lt;li&gt;Adjacent houses cannot both be robbed&lt;/li&gt;
&lt;li&gt;Output: return the maximum amount of money that can be robbed&lt;/li&gt;
&lt;li&gt;Constraints: &lt;code&gt;1 &amp;lt;= nums.length &amp;lt;= 100&lt;/code&gt;, &lt;code&gt;0 &amp;lt;= nums[i] &amp;lt;= 400&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="examples"&gt;Examples&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: nums = [1,2,3,1]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 4
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: rob indices 0 and 2, for 1 + 3 = 4
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: nums = [2,7,9,3,1]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 12
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: rob indices 0, 2, and 4, for 2 + 9 + 1 = 12
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This article uses Python only and derives 1D DP from the conflict between two choices.&lt;/p&gt;</description></item><item><title>LeetCode 70: Climbing Stairs, Deriving 1D DP from dp[i]</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/70-climbing-stairs/</link><pubDate>Sun, 03 May 2026 14:33:39 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/70-climbing-stairs/</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;h3 id="input-and-output"&gt;Input and Output&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Input: an integer &lt;code&gt;n&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Meaning: climb to the top of the &lt;code&gt;n&lt;/code&gt;-step staircase&lt;/li&gt;
&lt;li&gt;Each move can climb &lt;code&gt;1&lt;/code&gt; or &lt;code&gt;2&lt;/code&gt; steps&lt;/li&gt;
&lt;li&gt;Output: return the number of distinct ways to reach the top&lt;/li&gt;
&lt;li&gt;Constraints: &lt;code&gt;1 &amp;lt;= n &amp;lt;= 45&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="examples"&gt;Examples&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: n = 2
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 2
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: 1+1, 2
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: n = 3
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 3
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: 1+1+1, 1+2, 2+1
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This article uses Python only and derives the final solution step by step from the meaning of &lt;code&gt;dp[i]&lt;/code&gt;.&lt;/p&gt;</description></item><item><title>LeetCode 746: Min Cost Climbing Stairs, Deriving DP from the Top Position</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/746-min-cost-climbing-stairs/</link><pubDate>Sun, 03 May 2026 14:33:39 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/746-min-cost-climbing-stairs/</guid><description>&lt;h2 id="problem"&gt;Problem&lt;/h2&gt;
&lt;h3 id="input-and-output"&gt;Input and Output&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Input: an integer array &lt;code&gt;cost&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;cost[i]&lt;/code&gt; is the cost of stepping on stair &lt;code&gt;i&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Each move can climb &lt;code&gt;1&lt;/code&gt; or &lt;code&gt;2&lt;/code&gt; steps&lt;/li&gt;
&lt;li&gt;You may start from index &lt;code&gt;0&lt;/code&gt; or index &lt;code&gt;1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Output: return the minimum cost to reach the top&lt;/li&gt;
&lt;li&gt;Constraints: &lt;code&gt;2 &amp;lt;= cost.length &amp;lt;= 1000&lt;/code&gt;, &lt;code&gt;0 &amp;lt;= cost[i] &amp;lt;= 999&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="examples"&gt;Examples&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: cost = [10,15,20]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 15
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Explanation: start from index 1, pay 15, then reach the top directly
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: cost = [1,100,1,1,1,100,1,1,100,1]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: 6
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="start-from-the-top-position-of-101520"&gt;Start from the Top Position of [10,15,20]&lt;/h2&gt;
&lt;p&gt;Look at the small example:&lt;/p&gt;</description></item><item><title>LeetCode 78: Subsets, Derive the startIndex Backtracking Template</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/backtracking/78-subsets/</link><pubDate>Sun, 03 May 2026 14:25:07 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/backtracking/78-subsets/</guid><description>&lt;h2 id="problem-requirement"&gt;Problem Requirement&lt;/h2&gt;
&lt;h3 id="input--output"&gt;Input / Output&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;nums&lt;/code&gt;, with &lt;code&gt;1 &amp;lt;= nums.length &amp;lt;= 10&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Value range: &lt;code&gt;-10 &amp;lt;= nums[i] &amp;lt;= 10&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;All elements in &lt;code&gt;nums&lt;/code&gt; are distinct&lt;/li&gt;
&lt;li&gt;Output: return all possible subsets of &lt;code&gt;nums&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Ordering: the result order does not matter, and subset element order is not the point&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="example"&gt;Example&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: nums = [1,2,3]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This tutorial builds one minimal Python solution.&lt;/p&gt;
&lt;h2 id="start-from-the-search-tree-for-12"&gt;Start From the Search Tree for &lt;code&gt;[1,2]&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;The smallest branching example is:&lt;/p&gt;</description></item><item><title>LeetCode 90: Subsets II, Derive Layer-Level Deduplication</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/backtracking/90-subsets-ii/</link><pubDate>Sun, 03 May 2026 14:25:07 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/backtracking/90-subsets-ii/</guid><description>&lt;h2 id="problem-requirement"&gt;Problem Requirement&lt;/h2&gt;
&lt;h3 id="input--output"&gt;Input / Output&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Input: &lt;code&gt;nums&lt;/code&gt;, with &lt;code&gt;1 &amp;lt;= nums.length &amp;lt;= 10&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Value range: &lt;code&gt;-10 &amp;lt;= nums[i] &amp;lt;= 10&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;nums&lt;/code&gt; may contain duplicates&lt;/li&gt;
&lt;li&gt;Output: return all unique subsets&lt;/li&gt;
&lt;li&gt;Ordering: the result order does not matter, but the same value sequence may appear only once&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="example"&gt;Example&lt;/h3&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Input: nums = [1,2,2]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This tutorial starts with a correct but wasteful version, then derives sorting plus layer-level deduplication.&lt;/p&gt;
&lt;h2 id="start-from-duplicate-branches-in-122"&gt;Start From Duplicate Branches in &lt;code&gt;[1,2,2]&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;The smallest example that exposes the issue is:&lt;/p&gt;</description></item><item><title>Hot100: Binary Tree Maximum Path Sum (Tree DP / Single-Side Gain ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/124-binary-tree-maximum-path-sum/</link><pubDate>Mon, 20 Apr 2026 10:01:46 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/124-binary-tree-maximum-path-sum/</guid><description>A practical guide to LeetCode 124 covering the key design split: return only the best single-side gain upward, while using the full path through the current node to update a global answer.</description></item><item><title>Hot100: Binary Tree Right Side View (Level Order Last-Node Rule ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/199-binary-tree-right-side-view/</link><pubDate>Mon, 20 Apr 2026 10:01:46 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/199-binary-tree-right-side-view/</guid><description>A practical guide to LeetCode 199 covering why the right side view is just the last node of each level, plus two stable solutions: level-order BFS and right-first DFS.</description></item><item><title>Hot100: Construct Binary Tree from Preorder and Inorder Traversal (Indexed Divide-and-Conquer ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/105-construct-binary-tree-from-preorder-and-inorder-traversal/</link><pubDate>Mon, 20 Apr 2026 10:01:46 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/105-construct-binary-tree-from-preorder-and-inorder-traversal/</guid><description>A practical guide to LeetCode 105 covering how preorder chooses the root, how inorder splits the subtrees, and how a hash map plus index recursion reduces reconstruction to O(n).</description></item><item><title>Hot100: Convert Sorted Array to Binary Search Tree (Midpoint Divide-and-Conquer ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/108-convert-sorted-array-to-binary-search-tree/</link><pubDate>Mon, 20 Apr 2026 10:01:46 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/108-convert-sorted-array-to-binary-search-tree/</guid><description>A practical guide to LeetCode 108 covering why the midpoint is the natural root, how sorted order and balance requirements work together, and how to build the BST with stable index recursion.</description></item><item><title>Hot100: Flatten Binary Tree to Linked List (Reverse Preorder Rewiring ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/114-flatten-binary-tree-to-linked-list/</link><pubDate>Mon, 20 Apr 2026 10:01:46 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/114-flatten-binary-tree-to-linked-list/</guid><description>A practical guide to LeetCode 114 covering why the flattened list must follow preorder order and how reverse preorder with a prev pointer gives a stable in-place rewiring strategy.</description></item><item><title>Hot100: Kth Smallest Element in a BST (Inorder Counting / Early Stop ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/230-kth-smallest-element-in-a-bst/</link><pubDate>Mon, 20 Apr 2026 10:01:46 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/230-kth-smallest-element-in-a-bst/</guid><description>A practical guide to LeetCode 230 covering why inorder traversal of a BST is sorted, how to count visits with an explicit stack, and how to stop immediately at the k-th node.</description></item><item><title>Hot100: Add Two Numbers Linked-List Carry Simulation ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/2-add-two-numbers/</link><pubDate>Mon, 20 Apr 2026 09:36:56 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/2-add-two-numbers/</guid><description>Add two non-negative integers stored in reverse-order linked lists by simulating grade-school addition with carry propagation. This ACERS guide derives the one-pass solution and includes runnable multi-language implementations.</description></item><item><title>Hot100: LRU Cache Hash Table + Doubly Linked List O(1) ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/146-lru-cache/</link><pubDate>Mon, 20 Apr 2026 09:36:56 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/146-lru-cache/</guid><description>Design an LRU cache where both get and put run in O(1) average time by combining a hash table with a doubly linked list. This ACERS guide derives the data-structure split and includes runnable multi-language implementations.</description></item><item><title>Hot100: Remove Nth Node From End of List One-Pass Two-Pointer ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/19-remove-nth-node-from-end-of-list/</link><pubDate>Mon, 20 Apr 2026 09:36:56 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/19-remove-nth-node-from-end-of-list/</guid><description>Remove the n-th node from the end of a singly linked list by turning backward counting into a fixed-gap two-pointer problem. This ACERS guide derives the one-pass solution and includes runnable multi-language code.</description></item><item><title>Hot100: Diameter of Binary Tree (Tree DP / Height Return ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/543-diameter-of-binary-tree/</link><pubDate>Sun, 19 Apr 2026 15:51:55 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/543-diameter-of-binary-tree/</guid><description>A practical guide to LeetCode 543 covering the key split between returned height and global diameter updates, plus engineering mappings and runnable multi-language implementations.</description></item><item><title>Hot100: Lowest Common Ancestor of a Binary Tree (Postorder Return Semantics ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/236-lowest-common-ancestor-of-a-binary-tree/</link><pubDate>Sun, 19 Apr 2026 15:51:55 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/236-lowest-common-ancestor-of-a-binary-tree/</guid><description>A practical guide to LeetCode 236 covering the return-value meaning in postorder recursion, when the current node becomes the answer, and why a node can be its own ancestor.</description></item><item><title>Hot100: Validate Binary Search Tree (Range Constraints / Inorder ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/98-validate-binary-search-tree/</link><pubDate>Sun, 19 Apr 2026 15:13:19 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/98-validate-binary-search-tree/</guid><description>A practical guide to LeetCode 98 covering ancestor range constraints, why parent-only checks fail, and two stable solutions: recursive bounds and inorder validation.</description></item><item><title>Hot100: N-Queens Incremental Build Tutorial</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/backtracking/51-n-queens/</link><pubDate>Sun, 19 Apr 2026 14:49:56 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/backtracking/51-n-queens/</guid><description>A teaching-first incremental tutorial for LeetCode 51 that grows the N-Queens solution from a tiny example and a minimal DFS into column and diagonal state optimization.</description></item><item><title>Hot100: Palindrome Partitioning (Backtracking / Palindrome Table ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/backtracking/131-palindrome-partitioning/</link><pubDate>Sun, 19 Apr 2026 14:49:56 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/backtracking/131-palindrome-partitioning/</guid><description>A practical guide to LeetCode 131 that builds string-partition backtracking from scratch and shows why a palindrome table makes the search cleaner and more reusable.</description></item><item><title>LeetCode 216: Combination Sum III (Backtracking / Fixed-Length Search ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/216-combination-sum-iii/</link><pubDate>Fri, 17 Apr 2026 14:31:12 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/216-combination-sum-iii/</guid><description>Learn LeetCode 216 by deriving fixed-length combination search, use-once recursion, and bounded 1..9 pruning from the problem itself.</description></item><item><title>LeetCode 40: Combination Sum II (Backtracking / Same-Layer Dedup ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/40-combination-sum-ii/</link><pubDate>Fri, 17 Apr 2026 14:31:10 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/40-combination-sum-ii/</guid><description>Learn LeetCode 40 by deriving same-layer duplicate skipping, use-once recursion, and sorted pruning from the problem itself.</description></item><item><title>Hot100: Combination Sum (Backtracking / Pruning ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/backtracking/39-combination-sum/</link><pubDate>Wed, 08 Apr 2026 16:22:57 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/backtracking/39-combination-sum/</guid><description>A practical guide to LeetCode 39 that builds combination backtracking from scratch, explains remain-based state, and shows why sorting makes pruning safe.</description></item><item><title>Hot100: Permutations (used[] Backtracking ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/backtracking/46-permutations/</link><pubDate>Fri, 03 Apr 2026 17:54:22 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/backtracking/46-permutations/</guid><description>A practical guide to LeetCode 46 covering used[] state tracking, leaf-only collection, and runnable multi-language implementations.</description></item><item><title>LeetCode 133: Clone Graph Hash Map + DFS/BFS ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/133-clone-graph/</link><pubDate>Thu, 19 Mar 2026 13:18:26 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/133-clone-graph/</guid><description>Clone a connected undirected graph by mapping original nodes to cloned nodes, with DFS and BFS variants, cycle handling, correctness reasoning, and runnable implementations in six languages.</description></item><item><title>Hot100: Binary Tree Level Order Traversal (BFS / DFS ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/102-binary-tree-level-order-traversal/</link><pubDate>Mon, 16 Mar 2026 13:00:56 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/102-binary-tree-level-order-traversal/</guid><description>A practical guide to LeetCode 102 covering level-by-level BFS, level-size boundaries, DFS depth buckets, and runnable multi-language implementations.</description></item><item><title>Hot100: Symmetric Tree (Mirror Recursion / BFS ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/101-symmetric-tree/</link><pubDate>Mon, 16 Mar 2026 13:00:55 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/101-symmetric-tree/</guid><description>A practical guide to LeetCode 101 covering mirror recursion, pairwise BFS checks, symmetry contracts, and runnable multi-language implementations.</description></item><item><title>Hot100: Same Tree (Synchronous Recursion / BFS ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/100-same-tree/</link><pubDate>Mon, 16 Mar 2026 13:00:54 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/100-same-tree/</guid><description>A practical guide to LeetCode 100 covering synchronous recursion, pairwise BFS validation, structural equivalence, and runnable multi-language implementations.</description></item><item><title>Hot100: Invert Binary Tree (Recursion / BFS ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/226-invert-binary-tree/</link><pubDate>Fri, 06 Mar 2026 17:58:23 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/226-invert-binary-tree/</guid><description>A practical guide to LeetCode 226 covering tree mirroring, recursive left-right swaps, BFS traversal, and engineering mappings.</description></item><item><title>Hot100: Maximum Depth of Binary Tree (DFS / BFS ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/104-maximum-depth-of-binary-tree/</link><pubDate>Fri, 06 Mar 2026 17:58:22 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/104-maximum-depth-of-binary-tree/</guid><description>A practical guide to LeetCode 104 covering the depth definition, recursive DFS, level-order BFS, engineering mappings, and runnable multi-language implementations.</description></item><item><title>Hot100: Binary Tree Inorder Traversal (Recursion / Stack ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/94-binary-tree-inorder-traversal/</link><pubDate>Fri, 06 Mar 2026 17:58:21 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/binary-tree/94-binary-tree-inorder-traversal/</guid><description>A practical guide to LeetCode 94 covering left-root-right traversal, recursion, explicit stacks, engineering mappings, and runnable multi-language implementations.</description></item><item><title>LeetCode 146: LRU Cache Design with O(1) Hash Map + Doubly Linked List</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/146-lru-cache/</link><pubDate>Thu, 12 Feb 2026 13:51:08 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/146-lru-cache/</guid><description>Implement LRUCache with O(1) average get/put by combining a hash map for lookup and a doubly linked list for recency order. Includes ACERS reasoning, engineering mapping, and runnable multi-language code.</description></item><item><title>LeetCode 19: Remove Nth Node From End of List (One-pass Two Pointers) ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/19-remove-nth-node-from-end-of-list/</link><pubDate>Thu, 12 Feb 2026 13:50:28 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/19-remove-nth-node-from-end-of-list/</guid><description>From naive two-pass traversal to one-pass fast/slow pointers, this ACERS guide explains Remove Nth Node From End of List with correctness intuition, edge cases, engineering mappings, and runnable multi-language code.</description></item><item><title>LeetCode 138: Copy List with Random Pointer — A Complete Deep-Copy Breakdown</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/linked-list/138-copy-list-with-random-pointer/</link><pubDate>Wed, 11 Feb 2026 07:59:32 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/linked-list/138-copy-list-with-random-pointer/</guid><description>The core of copying a random-pointer list is mapping original node identity to copied node identity, then rebuilding next/random pointers. This article uses the ACERS structure to cover intuition, engineering analogies, pitfalls, and runnable multi-language implementations.</description></item><item><title>LeetCode 2: Add Two Numbers from Naive to Optimal Carry Simulation</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/2-add-two-numbers/</link><pubDate>Wed, 11 Feb 2026 07:54:26 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/2-add-two-numbers/</guid><description>Add two non-negative integers represented by reverse-order linked lists. This ACERS-style guide explains digit-by-digit carry propagation with engineering mappings and runnable multi-language code.</description></item><item><title>Hot100: Sort List Linked-List Merge Sort ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/148-sort-list/</link><pubDate>Tue, 10 Feb 2026 17:07:38 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/148-sort-list/</guid><description>Sort a singly linked list in O(n log n) time using split + recursive merge sort. This guide explains derivation, invariants, engineering mappings, and runnable multi-language implementations.</description></item><item><title>Hot100: Merge K Sorted Lists Divide-and-Conquer O(N log k) ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/23-merge-k-sorted-lists/</link><pubDate>Tue, 10 Feb 2026 17:05:53 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/23-merge-k-sorted-lists/</guid><description>Upgrade from LeetCode 21 to k-way merge: derive why sequential merge degrades, then use divide-and-conquer to reach O(N log k), with heap comparison and runnable multi-language implementations.</description></item><item><title>Hot100: Linked List Cycle II Floyd Detection + Entry Localization ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/142-linked-list-cycle-ii/</link><pubDate>Tue, 10 Feb 2026 10:47:56 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/142-linked-list-cycle-ii/</guid><description>Return the first node where a singly linked list enters a cycle without modifying the list: use Floyd fast/slow pointers to detect a meeting point, then reset one pointer to head and move both one step to localize the entry in O(n) time and O(1) space.</description></item><item><title>Hot100: Merge Two Sorted Lists Sentinel Two-Pointer Merge ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/21-merge-two-sorted-lists/</link><pubDate>Tue, 10 Feb 2026 10:47:02 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/21-merge-two-sorted-lists/</guid><description>Merge two sorted linked lists in O(m+n) with sentinel node and two pointers, with iterative and recursive comparison, engineering mapping, and runnable multi-language implementations.</description></item><item><title>Hot100: First Missing Positive In-Place Index Placement ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/41-first-missing-positive/</link><pubDate>Tue, 10 Feb 2026 10:25:53 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/41-first-missing-positive/</guid><description>Find the first missing positive in O(n) time and O(1) extra space using in-place index placement (value x should be placed at index x-1), with engineering mapping, pitfalls, and runnable multi-language implementations.</description></item><item><title>Hot100: Reverse Nodes in k-Group Group-Wise In-Place ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/25-reverse-nodes-in-k-group/</link><pubDate>Tue, 10 Feb 2026 10:25:53 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/25-reverse-nodes-in-k-group/</guid><description>Reverse a linked list in groups of k nodes in-place, leaving the last group unchanged if its size is smaller than k. This guide presents a dummy-node + kth-scan + in-place reversal template in O(n) time and O(1) extra space.</description></item><item><title>Hot100: Reorder List In-Place Split-Reverse-Merge ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/143-reorder-list/</link><pubDate>Tue, 10 Feb 2026 09:57:31 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/143-reorder-list/</guid><description>Reorder a linked list to L0-&amp;gt;Ln-&amp;gt;L1-&amp;gt;Ln-1... in O(n) time and O(1) extra space using split, reverse, and alternating merge, with derivation, pitfalls, and runnable multi-language implementations.</description></item><item><title>Hot100: Reverse Linked List II Dummy Node + Head-Insertion ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/92-reverse-linked-list-ii/</link><pubDate>Tue, 10 Feb 2026 09:56:14 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/92-reverse-linked-list-ii/</guid><description>Reverse only the interval [left, right] in a singly linked list using a dummy node and in-place head insertion. O(n) time, O(1) extra space, with derivation, pitfalls, and runnable multi-language implementations.</description></item><item><title>Hot100: Linked List Cycle Floyd Fast/Slow Pointer ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/141-linked-list-cycle/</link><pubDate>Tue, 10 Feb 2026 08:55:58 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/141-linked-list-cycle/</guid><description>Detect whether a singly linked list has a cycle using Floyd fast/slow pointers in O(n) time and O(1) extra space, with proof intuition, pitfalls, engineering mapping, and runnable multi-language implementations.</description></item><item><title>Hot100: Palindrome Linked List Fast/Slow + Reverse Second Half O(1) Space ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/234-palindrome-linked-list/</link><pubDate>Mon, 09 Feb 2026 17:38:32 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/234-palindrome-linked-list/</guid><description>Check whether a singly linked list is a palindrome in O(n) time and O(1) extra space: find middle with fast/slow pointers, reverse second half, compare, then restore list structure.</description></item><item><title>Hot100: Reverse Linked List Three-Pointer Iterative/Recursive ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/206-reverse-linked-list/</link><pubDate>Mon, 09 Feb 2026 17:27:59 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/206-reverse-linked-list/</guid><description>Reverse a singly linked list in O(n) time and O(1) extra space with the three-pointer iterative template, with recursive comparison, engineering mapping, and runnable multi-language implementations.</description></item><item><title>Hot100: Subarray Sum Equals K Prefix Sum + Hash Map ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/560-subarray-sum-equals-k/</link><pubDate>Mon, 09 Feb 2026 13:19:45 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/560-subarray-sum-equals-k/</guid><description>Count subarrays whose sum equals k in O(n) using prefix sum and frequency hash map, with engineering scenarios, pitfalls, and runnable multi-language implementations.</description></item><item><title>Hot100: Intersection of Two Linked Lists Two-Pointer Switch-Head O(1) Space ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/160-intersection-of-two-linked-lists/</link><pubDate>Mon, 09 Feb 2026 09:26:37 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/160-intersection-of-two-linked-lists/</guid><description>Find the intersection node of two singly linked lists without modifying structure: two pointers switching heads synchronize in O(m+n) time and O(1) extra space, with derivation, engineering mapping, and multi-language implementations.</description></item><item><title>Path Sum III: Prefix Sum + Hash Map Counting Downward Paths (LeetCode 437) ACERS Guide</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/437-path-sum-iii/</link><pubDate>Wed, 04 Feb 2026 16:02:26 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/437-path-sum-iii/</guid><description>Count downward paths in a binary tree whose sum equals targetSum in O(n) using prefix sums and a frequency hash map, with derivation, engineering mapping, and multi-language implementations.</description></item><item><title>Hot100: Spiral Matrix (Boundary Shrinking Simulation ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/54-spiral-matrix/</link><pubDate>Tue, 03 Feb 2026 10:01:50 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/54-spiral-matrix/</guid><description>Traverse a matrix in clockwise spiral order in O(mn) using boundary shrinking. Includes engineering scenarios, pitfalls, and multi-language implementations.</description></item><item><title>LeetCode 42: How Much Rain Water Can an Elevation Map Hold?</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/42-trapping-rain-water/</link><pubDate>Sat, 24 Jan 2026 10:40:53 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/42-trapping-rain-water/</guid><description>Start with one position, derive boundary arrays and an O(1)-space two-pointer solution, then connect the same boundary model to a monotonic stack.</description></item><item><title>Hot100: Maximum Subarray (Kadane O(n) ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/53-maximum-subarray/</link><pubDate>Fri, 23 Jan 2026 13:21:02 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/hot100/53-maximum-subarray/</guid><description>Use Kadane&amp;#39;s algorithm to compute the maximum subarray sum in O(n). Includes engineering scenarios, pitfalls, and multi-language implementations.</description></item><item><title>LeetCode 1437: Check If All 1's Are at Least K Apart (ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/1437-check-if-all-ones-are-at-least-k-places-away/</link><pubDate>Thu, 22 Jan 2026 10:49:42 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/1437-check-if-all-ones-are-at-least-k-places-away/</guid><description>One-pass check to ensure all 1s are at least k apart. Includes engineering scenarios, pitfalls, and multi-language implementations.</description></item><item><title>LeetCode 231: Power of Two (Bit Trick O(1) ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/231-power-of-two/</link><pubDate>Wed, 21 Jan 2026 14:06:56 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/231-power-of-two/</guid><description>Judge whether an integer is a power of two in O(1) time using bit tricks. Includes engineering scenarios, pitfalls, and multi-language solutions.</description></item><item><title>LeetCode 1456: Maximum Number of Vowels in a Substring of Given Length (ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/1456-maximum-number-of-vowels-in-a-substring-of-given-length/</link><pubDate>Tue, 20 Jan 2026 13:40:45 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/1456-maximum-number-of-vowels-in-a-substring-of-given-length/</guid><description>Use a fixed-size sliding window to compute the maximum number of vowels in O(n). Includes engineering scenarios and multi-language implementations.</description></item><item><title>LeetCode 239: Sliding Window Maximum</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/239-sliding-window-maximum/</link><pubDate>Mon, 19 Jan 2026 17:46:14 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/239-sliding-window-maximum/</guid><description>Solve LeetCode 239 by defining complete windows, building a correct scan, and deriving an O(n) index-deque solution.</description></item><item><title>LeetCode 1512: Number of Good Pairs (Hash Counting ACERS Guide)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/1512-number-of-good-pairs/</link><pubDate>Tue, 30 Dec 2025 11:40:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/1512-number-of-good-pairs/</guid><description>Solve Good Pairs with one-pass hash counting, plus engineering scenarios, complexity, and multi-language solutions.</description></item><item><title>LeetCode 1: Two Sum (Hash Map ACERS Summary)</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/1-two-sum/</link><pubDate>Thu, 04 Dec 2025 11:10:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/1-two-sum/</guid><description>&lt;h1 id="leetcode-1-two-sum"&gt;LeetCode 1: Two Sum&lt;/h1&gt;
&lt;h2 id="summary"&gt;Summary&lt;/h2&gt;
&lt;p&gt;Find two indices such that &lt;code&gt;nums[i] + nums[j] = target&lt;/code&gt;. Use a hash map for O(n) time.&lt;/p&gt;
&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;Iterate and store &lt;code&gt;value -&amp;gt; index&lt;/code&gt;. For each number &lt;code&gt;x&lt;/code&gt;, check if &lt;code&gt;target - x&lt;/code&gt; exists.&lt;/p&gt;
&lt;h2 id="complexity"&gt;Complexity&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Time: O(n)&lt;/li&gt;
&lt;li&gt;Space: O(n)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="python-reference-implementation"&gt;Python reference implementation&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;def&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;two_sum&lt;/span&gt;(nums, target):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; seen &lt;span style="color:#f92672"&gt;=&lt;/span&gt; {}
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; i, x &lt;span style="color:#f92672"&gt;in&lt;/span&gt; enumerate(nums):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; y &lt;span style="color:#f92672"&gt;=&lt;/span&gt; target &lt;span style="color:#f92672"&gt;-&lt;/span&gt; x
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; y &lt;span style="color:#f92672"&gt;in&lt;/span&gt; seen:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; [seen[y], i]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; seen[x] &lt;span style="color:#f92672"&gt;=&lt;/span&gt; i
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>LeetCode 2300: Successful Pairs of Spells and Potions</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/2300-successful-pairs-of-spells-and-potions/</link><pubDate>Thu, 04 Dec 2025 11:10:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/2300-successful-pairs-of-spells-and-potions/</guid><description>&lt;h1 id="leetcode-2300-successful-pairs-of-spells-and-potions"&gt;LeetCode 2300: Successful Pairs of Spells and Potions&lt;/h1&gt;
&lt;h2 id="summary"&gt;Summary&lt;/h2&gt;
&lt;p&gt;For each spell, count how many potions make &lt;code&gt;spell * potion &amp;gt;= success&lt;/code&gt;. Sort potions and binary search the threshold.&lt;/p&gt;
&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Sort potions.&lt;/li&gt;
&lt;li&gt;For each spell, compute &lt;code&gt;need = ceil(success / spell)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use binary search to find the first potion &amp;gt;= need.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="complexity"&gt;Complexity&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Time: O(n log n)&lt;/li&gt;
&lt;li&gt;Space: O(1) extra (or O(n) if sorting a copy)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="python-reference-implementation"&gt;Python reference implementation&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; bisect
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#f92672"&gt;import&lt;/span&gt; math
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;def&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;successful_pairs&lt;/span&gt;(spells, potions, success):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; potions &lt;span style="color:#f92672"&gt;=&lt;/span&gt; sorted(potions)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; n &lt;span style="color:#f92672"&gt;=&lt;/span&gt; len(potions)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; res &lt;span style="color:#f92672"&gt;=&lt;/span&gt; []
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; s &lt;span style="color:#f92672"&gt;in&lt;/span&gt; spells:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; need &lt;span style="color:#f92672"&gt;=&lt;/span&gt; (success &lt;span style="color:#f92672"&gt;+&lt;/span&gt; s &lt;span style="color:#f92672"&gt;-&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;) &lt;span style="color:#f92672"&gt;//&lt;/span&gt; s
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; idx &lt;span style="color:#f92672"&gt;=&lt;/span&gt; bisect&lt;span style="color:#f92672"&gt;.&lt;/span&gt;bisect_left(potions, need)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; res&lt;span style="color:#f92672"&gt;.&lt;/span&gt;append(n &lt;span style="color:#f92672"&gt;-&lt;/span&gt; idx)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; res
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>LeetCode 2379: Minimum Recolors to Get K Consecutive Black Blocks</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/2379-minimum-recolors-to-get-k-consecutive-black-blocks/</link><pubDate>Thu, 04 Dec 2025 11:10:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/2379-minimum-recolors-to-get-k-consecutive-black-blocks/</guid><description>&lt;h1 id="leetcode-2379-minimum-recolors-to-get-k-consecutive-black-blocks"&gt;LeetCode 2379: Minimum Recolors to Get K Consecutive Black Blocks&lt;/h1&gt;
&lt;h2 id="summary"&gt;Summary&lt;/h2&gt;
&lt;p&gt;Given a string of &amp;lsquo;B&amp;rsquo; and &amp;lsquo;W&amp;rsquo;, find the minimum recolors to make a substring of length &lt;code&gt;k&lt;/code&gt; all black.&lt;/p&gt;
&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;Use a sliding window of length &lt;code&gt;k&lt;/code&gt; and count the number of whites in the window. The minimum whites across all windows is the answer.&lt;/p&gt;
&lt;h2 id="complexity"&gt;Complexity&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Time: O(n)&lt;/li&gt;
&lt;li&gt;Space: O(1)&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="python-reference-implementation"&gt;Python reference implementation&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;def&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;minimum_recolors&lt;/span&gt;(blocks, k):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; whites &lt;span style="color:#f92672"&gt;=&lt;/span&gt; sum(&lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; c &lt;span style="color:#f92672"&gt;in&lt;/span&gt; blocks[:k] &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; c &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;W&amp;#39;&lt;/span&gt;)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ans &lt;span style="color:#f92672"&gt;=&lt;/span&gt; whites
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; i &lt;span style="color:#f92672"&gt;in&lt;/span&gt; range(k, len(blocks)):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; blocks[i&lt;span style="color:#f92672"&gt;-&lt;/span&gt;k] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;W&amp;#39;&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; whites &lt;span style="color:#f92672"&gt;-=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; blocks[i] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#e6db74"&gt;&amp;#39;W&amp;#39;&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; whites &lt;span style="color:#f92672"&gt;+=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ans &lt;span style="color:#f92672"&gt;=&lt;/span&gt; min(ans, whites)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; ans
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item><item><title>LeetCode 2841: Maximum Sum of Almost Unique Subarray</title><link>https://jeanphilogong.github.io/jeanblog/alg/leetcode/2841-maximum-sum-of-almost-unique-subarray/</link><pubDate>Thu, 04 Dec 2025 11:10:00 +0800</pubDate><guid>https://jeanphilogong.github.io/jeanblog/alg/leetcode/2841-maximum-sum-of-almost-unique-subarray/</guid><description>&lt;h1 id="leetcode-2841-maximum-sum-of-almost-unique-subarray"&gt;LeetCode 2841: Maximum Sum of Almost Unique Subarray&lt;/h1&gt;
&lt;h2 id="summary"&gt;Summary&lt;/h2&gt;
&lt;p&gt;Given an array, window size &lt;code&gt;k&lt;/code&gt;, and threshold &lt;code&gt;m&lt;/code&gt;, find the maximum sum of any length-&lt;code&gt;k&lt;/code&gt; subarray that contains at least &lt;code&gt;m&lt;/code&gt; distinct elements.&lt;/p&gt;
&lt;h2 id="approach"&gt;Approach&lt;/h2&gt;
&lt;p&gt;Use a sliding window with a frequency map, track window sum and number of distinct values.&lt;/p&gt;
&lt;h2 id="complexity"&gt;Complexity&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Time: O(n)&lt;/li&gt;
&lt;li&gt;Space: O(n) for frequency map&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="python-reference-implementation"&gt;Python reference implementation&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-python" data-lang="python"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#66d9ef"&gt;def&lt;/span&gt; &lt;span style="color:#a6e22e"&gt;max_sum_almost_unique&lt;/span&gt;(nums, m, k):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;from&lt;/span&gt; collections &lt;span style="color:#f92672"&gt;import&lt;/span&gt; defaultdict
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; count &lt;span style="color:#f92672"&gt;=&lt;/span&gt; defaultdict(int)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; distinct &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; window_sum &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ans &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;for&lt;/span&gt; i, x &lt;span style="color:#f92672"&gt;in&lt;/span&gt; enumerate(nums):
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; window_sum &lt;span style="color:#f92672"&gt;+=&lt;/span&gt; x
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; count[x] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; distinct &lt;span style="color:#f92672"&gt;+=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; count[x] &lt;span style="color:#f92672"&gt;+=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; i &lt;span style="color:#f92672"&gt;&amp;gt;=&lt;/span&gt; k:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; y &lt;span style="color:#f92672"&gt;=&lt;/span&gt; nums[i &lt;span style="color:#f92672"&gt;-&lt;/span&gt; k]
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; window_sum &lt;span style="color:#f92672"&gt;-=&lt;/span&gt; y
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; count[y] &lt;span style="color:#f92672"&gt;-=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; count[y] &lt;span style="color:#f92672"&gt;==&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;0&lt;/span&gt;:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; distinct &lt;span style="color:#f92672"&gt;-=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;if&lt;/span&gt; i &lt;span style="color:#f92672"&gt;&amp;gt;=&lt;/span&gt; k &lt;span style="color:#f92672"&gt;-&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt; &lt;span style="color:#f92672"&gt;and&lt;/span&gt; distinct &lt;span style="color:#f92672"&gt;&amp;gt;=&lt;/span&gt; m:
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; ans &lt;span style="color:#f92672"&gt;=&lt;/span&gt; max(ans, window_sum)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#66d9ef"&gt;return&lt;/span&gt; ans
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</description></item></channel></rss>