<?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>Dynamic Programming on Jeanphilo Blog</title><link>https://jeanphilogong.github.io/jeanblog/tags/dynamic-programming/</link><description>Recent content in Dynamic Programming on Jeanphilo Blog</description><generator>Hugo -- 0.168.0</generator><language>en-us</language><lastBuildDate>Thu, 08 Oct 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://jeanphilogong.github.io/jeanblog/tags/dynamic-programming/index.xml" rel="self" type="application/rss+xml"/><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 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 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>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></channel></rss>