You are given a binary string s containing only 0s and 1s.
Your task is to minimize the length of the longest consecutive substring of the same character by
performing at most k operations. In one operation, you can flip a single bit: change
a 0 to 1 or a 1 to 0.
Input:
A binary string s (length n), where 1 ≤ n ≤ 10^5.
An integer k (the maximum number of bit flips allowed), where 0 ≤ k ≤ n.
Output:
Return the minimum possible length of the longest consecutive substring of the same character after
performing at most k flips.
Examples
01 · Example 1
s = "00000" k = 2 return = 1
n/a
Constraints
🍋🍋More Salesforce problems
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Final Pod Counts After LogsOA · Seen May 2026
- Minimum Removals to Balance ArrayOA · Seen May 2026
- Key Teams in TreeOA · Seen Mar 2026
- System Energy ReductionOA · Seen Mar 2026
- Update Logs by Symmetric XOROA · Seen Mar 2026
- Count Palindromic Concatenation PairsOA · Seen Mar 2026
public int minimizeLengthOfLongestSubstring(String s, int k) {
// write your code here
}
s"00000"
k2
expected1
checking account