|
| 1 | +<h2><a href="https://leetcode.com/problems/max-consecutive-ones-iii/">1004. Max Consecutive Ones III</a></h2><h3>Medium</h3><hr><div><p>Given a binary array <code>nums</code> and an integer <code>k</code>, return <em>the maximum number of consecutive </em><code>1</code><em>'s in the array if you can flip at most</em> <code>k</code> <code>0</code>'s.</p> |
| 2 | + |
| 3 | +<p> </p> |
| 4 | +<p><strong>Example 1:</strong></p> |
| 5 | + |
| 6 | +<pre><strong>Input:</strong> nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2 |
| 7 | +<strong>Output:</strong> 6 |
| 8 | +<strong>Explanation:</strong> [1,1,1,0,0,<u><strong>1</strong>,1,1,1,1,<strong>1</strong></u>] |
| 9 | +Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.</pre> |
| 10 | + |
| 11 | +<p><strong>Example 2:</strong></p> |
| 12 | + |
| 13 | +<pre><strong>Input:</strong> nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3 |
| 14 | +<strong>Output:</strong> 10 |
| 15 | +<strong>Explanation:</strong> [0,0,<u>1,1,<strong>1</strong>,<strong>1</strong>,1,1,1,<strong>1</strong>,1,1</u>,0,0,0,1,1,1,1] |
| 16 | +Bolded numbers were flipped from 0 to 1. The longest subarray is underlined. |
| 17 | +</pre> |
| 18 | + |
| 19 | +<p> </p> |
| 20 | +<p><strong>Constraints:</strong></p> |
| 21 | + |
| 22 | +<ul> |
| 23 | + <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> |
| 24 | + <li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li> |
| 25 | + <li><code>0 <= k <= nums.length</code></li> |
| 26 | +</ul> |
| 27 | +</div> |
0 commit comments