Skip to content

Commit c3114f4

Browse files
committed
Problem description for Max Consecutive Ones II
1 parent e81caf7 commit c3114f4

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
# [Max Consecutive Ones II](https://leetcode.com/problems/max-consecutive-ones-ii) ![](https://img.shields.io/badge/Medium-orange)
3+
4+
<p>Given a binary array <code>nums</code>, return <em>the maximum number of consecutive </em><code>1</code><em>&#39;s in the array if you can flip at most one</em> <code>0</code>.</p>
5+
6+
<p>&nbsp;</p>
7+
<p><strong class="example">Example 1:</strong></p>
8+
9+
<pre>
10+
<strong>Input:</strong> nums = [1,0,1,1,0]
11+
<strong>Output:</strong> 4
12+
<strong>Explanation:</strong>
13+
- If we flip the first zero, nums becomes [1,1,1,1,0] and we have 4 consecutive ones.
14+
- If we flip the second zero, nums becomes [1,0,1,1,1] and we have 3 consecutive ones.
15+
The max number of consecutive ones is 4.
16+
</pre>
17+
18+
<p><strong class="example">Example 2:</strong></p>
19+
20+
<pre>
21+
<strong>Input:</strong> nums = [1,0,1,1,0,1]
22+
<strong>Output:</strong> 4
23+
<strong>Explanation:</strong>
24+
- If we flip the first zero, nums becomes [1,1,1,1,0,1] and we have 4 consecutive ones.
25+
- If we flip the second zero, nums becomes [1,0,1,1,1,1] and we have 4 consecutive ones.
26+
The max number of consecutive ones is 4.
27+
</pre>
28+
29+
<p>&nbsp;</p>
30+
<p><strong>Constraints:</strong></p>
31+
32+
<ul>
33+
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
34+
<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
35+
</ul>
36+
37+
<p>&nbsp;</p>
38+
<p><strong>Follow up:</strong> What if the input numbers come in one by one as an infinite stream? In other words, you can&#39;t store all numbers coming from the stream as it&#39;s too large to hold in memory. Could you solve it efficiently?</p>
39+
40+

0 commit comments

Comments
 (0)