How Many Flips?
Learn this problemProblem statement
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
minimumFlips(target: String) → int
Complete the function minimumFlips in the editor below.
minimumFlips has the following parameter(s):
- string target: a string of 0s and 1s to match
Returns
int: the minimum number of flips needed to obtain the target string
Examples
Example 1
target = "01011"return = 3Start 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
Unknown for nowMore JPMorgan Chase problems
- Bitwise XOR SubsequencesOA · Seen Jul 2026
- Array ChallengeOA · Seen Jun 2026
- Minimum Cores to Handle ProcessesOA · Seen Jun 2026
- About ShippingOA · Seen Jun 2026
- Count Dropped RequestsOA · Seen Jan 2026
- Generate Table of ContentsOA · Seen Jan 2026
- Calculate Net ProfitSeen Jun 2025
- Find Total WeightSeen Jun 2025