AmazonOA #199
Get Max Alternating Music
Estimated MediumJudge-ready
Topics (AI-labelled)Two PointersStrings
In a binary string you may flip one character at a time, at most k times. Find the maximum length of a contiguous substring in which every pair of adjacent characters differs. It is a substring, not a subsequence, and flips apply to single characters, not to whole ranges.
Input
The first line contains the binary string; the second line contains k. This site uses 1≤length≤200000, 0≤k≤200000.
Output
Output a single integer, the answer.
Example 1
Input:
0000
1
Output:
3
Example 2
Input:
01010
0
Output:
5
Example 3
Input:
111
2
Output:
3
Example notes
The answers are 3, 5 and 3.
Editorial
Loading solution…