Salesforce OA
Question Details
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...
Full Details
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 \u2264 n \u2264 10^5.
An integer k (the maximum number of bit flips allowed), where 0 \u2264 k \u2264 n.
Output:
Return the minimum possible length of the longest consecutive substring of the same character after performing at most k flips.
Sample test case
Input:
s = "00000"
k = 2
Output: 1
I solved it but didnt pass all test cases. I kinda knew my greedy approach using max heap would not work. How to approach this?
Edit: This problem was asked in Bloomberg recently as well
About This Question
This is a reported interview question from a bloomberg interview for a swe role during the oa round reported in 2024.