Smallest Substring With Identical Characters II
You are given a binary string s of length n and an integer numOps.
You are allowed to perform the following operation on s at most numOps times:
- Select any index
iwhere0 <= i < nand flips[i]. Ifs[i] == '1', changes[i]to'0', and vice versa.
You need to minimize the length of the longest substring of s such that all the characters in the substring are identical.
Return the minimum length after the operations.
Example 1
Input
s = "000001", numOps = 1Output
2By changing
s[2] to '1', s becomes "001001", whose longest substrings with identical characters have length 2.Example 2
Input
s = "0000", numOps = 2Output
1By changing
s[0] and s[2] to '1', s becomes "1010", so every longest substring with identical characters has length 1.Constraints
- 1 <= n == s.length <= 10^5
- s consists only of '0' and '1'.
- 0 <= numOps <= n