FastPrepMinimize Length of Longest Substring
Problems/Minimize Length of Longest Substring

Minimize Length of Longest Substring

Salesforce logoSalesforce● MediumOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

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) → int

Examples

Example 1

s = "00000"k = 2return = 1

n/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

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public int minimizeLengthOfLongestSubstring(String s, int k) {
      // write your code here
    }

}
Checking account…