Company: JPMorgan Chase - Code For Good - India Campus Hiring - 2026 Batch SI_24march
Difficulty: medium
You are given a binary string password consisting only of characters '0' and '1'. To be considered secure, the password must be split into non-overlapping substrings such that: Each substring has an even length Each substring contains only one type of character (all '0's or all '1's) Your task is to determine the minimum number of character flips required to make this division possible. Note: A flip changes a '0' to '1' or a '1' to '0'. Example Suppose password = "1110011000" Output: 3 Explanation: One optimal solution is to flip the zeros at positions 3, 4, and 7 to get "1111111100". This can be divided into two valid substrings: "11111111" and "00". Both substrings have even length and contain only one type of character. Constraints 2 ≤ length of password ≤ 10 5 The length of password is even. password contains only 1s and 0s. #include <bits/stdc++.h> /* * Complete the 'getMinFlips' function below. * * The function is expected to return an INTEGER. * The function accepts