411. Max Consecutive Ones With K Flips
MediumSliding Window
The array has only 0s and 1s. You may flip at most k zeros to ones. Print the length of the longest run of ones you can get.
Input format
Line 1: n k Line 2: n bits
Output format
The maximum length.
Example 1
Input
11 2 1 1 1 0 0 0 1 1 1 1 0
Output
6
Example 2
Input
19 3 0 0 1 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1
Output
10
Constraints
1 ≤ n ≤ 10⁵ 0 ≤ k ≤ n
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…