AmazonOA #200
Max Consecutive ON Servers
Estimated MediumJudge-ready
Topics (AI-labelled)Two PointersStrings
One operation chooses any contiguous range and flips every 0 and 1 in it; at most k operations are allowed. Find the length of the longest contiguous run of 1s at the end. Operations may overlap, and you do not have to use all k.
Input
The first line contains the binary string; the second line contains k. 1≤length≤200000, 1≤k≤200000.
Output
Output a single integer, the answer.
Example 1
Input:
00010
1
Output:
4
Example 2
Input:
1001
2
Output:
4
Example 3
Input:
11101010110011
2
Output:
8
Example notes
The answers are 4, 4 and 8; flipping the last two runs of 0s directly gives length 8, with no need for the complicated overlapping operations used in the source.
Editorial
Loading solution…