This is a verified interview question from Expedia. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Maximum Ones After Bit Flips - Expedia Online Assessment" covers key patterns like Arrays.
"Pattern : 8 QS( 2 DSA + 6 MCQS)  You are given a binary string `s` consisting only of `'0'` and `'1'`, and an integer `k`. In one operation, you may choose any index `i` (`0 ≤ i < n`) and flip the bit at that position: * `'0'` becomes `'1'` * `'1'` becomes `'0'` Perform **at most `k` operations**. Your task is to determine the **maximum possible number of `'1'`s** in the final string. ### Function Signature ```cpp int getMaximumOnes(string s, int k); ``` ### Parameters * `s` — a binary string. * `k` — the maximum number of operations allowed. ### Returns * An integer representing the maximum possible number of `'1'`s after performing at most `k` operations. --- ## Input Format The first line contains the binary string `s`. The second line contains an integer `k`. --- ## Output Format Print a single integer — the maximum possible number of `'1'`s after at most `k` operations. --- ## Constraints * `1 ≤ |s| ≤ 2 × 10^5` * `0 ≤ k ≤ |s|` * `s` contains only `'0'` and `'1'`. --- ## Sample Input 1 ``` 00011 2 ``` ## Sample Output 1 ``` 4 ``` ### Explanation Flip the bits at indices `0` and `1`. ``` 00011 ↓ 11011 ``` The resulting string contains `4` ones, which is the maximum possible. --- ## Sample Input 2 ``` 10110 1 ``` ## Sample Output 2 ``` 4 ``` ### Explanation Flip the bit at index `1`. ``` 10110 ↓ 11110 ``` The resulting string contains `4` ones. ---"
Join thousands of developers practicing for Expedia.