Company: Zomato
Difficulty: hard
A binary string data of length n is given. An inversion is a pair of indices (i, j) such that 0 ≤ i < j < n data[i] > data[j] Since the string is binary, this means an inversion occurs when data[i] = '1' and data[j] = '0' . You may perform the following operation at most maxFlips times: choose any position in the string and flip its bit (0 → 1 or 1 → 0). Determine the minimum possible number of inversions after applying at most maxFlips operations. Input Format Line 1: the binary string data . Line 2: the integer maxFlips . Output Format Print a single integer: the minimum number of inversions. Constraints 1 ≤ maxFlips ≤ n ≤ 5000 data consists only of the characters 0 and 1 Example Input 0110 2 Output 0 The optimal set of operations is to flip the bits at positions 1 and 2 (0-based indexing). Then data = 0000 , which has 0 inversions.