SalesforceOA #13
Find Minimum Idleness
Estimated HardJudge-ready
Topics (AI-labelled)Binary SearchGreedy
An a/b string records the GPU used each time, and you may flip at most switchCount positions. Find the minimum possible length of the longest run of identical characters. The original explanation contains invalid characters and a wrong example whose length shrinks after the change; this site keeps the rule that each flip changes exactly one character.
Input
The first line is a non-empty a/b string, and the second line is switchCount. On this site the length is 1..200000 and 0≤switchCount≤length.
Output
Output the minimum possible length of the longest run.
Example 1
Input:
aabbbbaaaa
2
Output:
2
Example 2
Input:
aaaa
0
Output:
4
Example 3
Input:
aabb
1
Output:
2
Example notes
The answers are 2, 4, and 2; the first example can be changed to aababbaaba, keeping the length at 10 with a longest run of 2.
Editorial
Loading solution…