Max Consecutive Ones III
MediumP2Coding
nums is a binary array (every element is 0 or 1). You may flip at most k zeros to ones. Return the length of the longest run of consecutive ones you can obtain.
Example 1
- Input
- nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2
- Output
- 6
Example 2
- Input
- nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3
- Output
- 10
Example 3
- Input
- nums = [1,1,1], k = 0
- Output
- 3
Constraints
- 1 <= nums.length <= 10^5
- nums[i] is 0 or 1
- 0 <= k <= nums.length
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 12. ⌘Enter runs, ⌘⇧Enter submits.