LeetCode 926, Medium. Topics: String, Dynamic Programming, Greedy. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 16 parametrized pytest cases, and a playground notebook:
Problem
<p>A binary string is monotone increasing if it consists of some number of <code>0</code>‘s (possibly none), followed by some number of <code>1</code>‘s (also possibly none).</p>
<p>You are given a binary string <code>s</code>. You can flip <code>s[i]</code> changing it from <code>0</code> to <code>1</code> or from <code>1</code> to <code>0</code>.</p>
<p>Return <em>the minimum number of flips to make </em><code>s</code><em> monotone increasing</em>.</p>
Examples
Constraints
- 1 <= s.length <= 10^5
- s[i] is either ‘0’ or ‘1’.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026