Back to course home
0% completed
Vote For New Content
Solution: Max Consecutive Ones III
Problem Statement
Given a binary array nums
containing only 0
and 1
and an integer k
, return the maximum number of consecutive 1's in the array if you can flip at most k 0's.
Examples
Example 1:
- Input: nums = [1, 0, 0, 1, 1, 0, 1, 1], k = 2
- Expected Output: 6
- Justification: By flipping
0
at the second and fifth index in the list, we get [1, 0, 1, 1, 1, 1, 1, 1], which has 6 consecutive 1s.
Example 2:
- Input: nums = [1, 0, 1, 1, 0, 0, 1, 1], k = 1
- Expected Output: 4
- Justification: By flipping `0
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page