FastPrepFastPrep
Problem Brief

How Many Flips?

FULLTIMEOA

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.

Function Description

Complete the function minimumFlips in the editor below.

minimumFlips has the following parameter(s):

  1. string target: a string of 0s and 1s to match

Returns

int: the minimum number of flips needed to obtain the target string

1Example 1

Input
target = "01011"
Output
3
Explanation

Start with a string of 5 zeros, the same length as the target.

Initial String -> 00000

Flip the 3rd digit -> 00111

Flip the 2nd digit -> 01000

Flip the 4th digit -> 01011

3 flips are required to reach the target. The return value is 3.

Constraints

Limits and guarantees your solution can rely on.

Unknown for now
public int minimumFlips(String target) {
    // write your code here
}
Input

target

"01011"

Output

3

Sign in to submit your solution.