Given a binary string, that is it contains only 0s and 1s. We need to make this string a sequence of alternate characters by flipping some of the bits, our goal is to minimize the number of bits to be flipped.
S = "001"
Explanation: We can flip the 0th bit to 1
to have "101".
S = "0001010111"
Explanation: We can flip the 1st and 8th bit
to have "0101010101".
You don't need to read input or print anything. Your task is to complete the function minFlips() which takes the string S as input and returns the minimum number of flips required.
Expected Time Complexity: O(|S|). Expected Auxiliary Space: O(1).