Company: Mckinsey data scientist IITB
Difficulty: medium
How Many Flips? Problem Description Start with an initial string of zeros. Choose any digit to flip. When a digit is flipped, its value and those to the right switch state between 0 and 1. Given a target string of binary digits, determine the minimum number of flips required to achieve the target. Examples Example 1: Input: target = "01011" Start with a string of 5 zeros, the same length string as the target. 0. Initial String -> "00000" 1. Flip the 3rd digit -> "00111" 2. Flip the 2nd digit -> "01000" 3. Flip the 4th digit -> "01011" Explanation: 3 flips are required to reach the target. The return value is 3. Example 2: Input: target = "1010" Start with a string of 4 zeros, the same length string as the target. 0. Initial String -> "0000" 1. Flip the 4th digit -> "0001" 2. Flip the 3rd digit -> "0010" 3. Flip the 2nd digit -> "0101" 4. Flip the 1st digit -> "1010" Explanation: 4 flips are required to reach the target, so return 4. Constraints 1 <= length of target <= 10 5 The t