SalesforceOA #32
Minimize Length of Longest Substring
Estimated HardJudge-ready
Topics (AI-labelled)Binary SearchGreedy
Given a binary string, flip at most k positions so that the longest run of consecutive identical characters is as short as possible, and output that minimum length.
Input
The input gives a binary string s and k. The full original bounds are in the statement body: 1≤|s|≤100000, 0≤k≤|s|; they must not be lost just because the Constraints section is empty.
Output
Output one integer answer.
Example 1
Input:
00000
2
Output:
1
Example 2
Input:
001100
1
Output:
2
Example 3
Input:
1
0
Output:
1
Example notes
The outputs of the three public examples are, in order: 1; 2; 1. They have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…