Minimize Length of Longest Substring
Updated
Problem statement
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.
Function
minimizeLengthOfLongestSubstring(s: String, k: int) → intExamples
Example 1
s = "00000"k = 2return = 1n/a
Constraints
🍋🍋
More Salesforce interview questions
- Count Subarrays With Product Equal to KOA · Seen Dec 2026
- Get Minimum TimeOA · Seen Nov 2026
- Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
- Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
- 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
- Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
- Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
- Get Message StatusOA · Seen Nov 2026
Similar questions at other companies
- Perfect SubstringAXQ Capital · OA
- Perfect Squares Matching a PatternNielsen · OA
- Count Proper Prefix MatchesAT&T · OAAT&T interview questions
- Maximum Valid Substring FrequencyMicrosoft · OAMicrosoft interview questions
- Same Substring Within BudgetJP Morgan Chase · OAJP Morgan Chase interview questions
- Longest Distinct StringSuperhuman · OASuperhuman interview questions
- K Smallest SubstringAkuna Capital · OAAkuna Capital interview questions
- Minimum Number of Non-Empty Disjoint SegmentsIBM · OAIBM interview questions
- Perfect SubstringsVisa · OAVisa interview questions
- Vowel SubstringSnowflake · OASnowflake interview questions