FastPrepMinimum Flips for Even Binary Runs
Problems/Minimum Flips for Even Binary Runs

Minimum Flips for Even Binary Runs

JP Morgan Chase logoJP Morgan Chase● EasyINTERNOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The first example and judged core task match the photographed source at about 100%.

You are given an even-length binary string password. In one flip, change a single 0 to 1 or a single 1 to 0.

After the flips, the whole string must be split into non-overlapping substrings such that:

  • Every substring has even length.
  • Every substring contains only one kind of character: all 0s or all 1s.

Return the minimum number of flips needed. You may choose any number of substrings, including one.

Function

getMinFlips(password: String) → int

Examples

Example 1

password = "1110011000"return = 3

Using zero-based positions, flip the zeros at positions 3, 4, and 7. The string becomes 1111111100. Split it into eight 1s followed by two 0s; both parts have even length and one character type.

The original consecutive pairs are 11, 10, 01, 10, and 00. Three pairs differ, and each requires at least one flip, so three flips are optimal.

Example 2

password = "001111"return = 0

The string already splits into 00 and 1111, of lengths two and four. Both parts are uniform and have even length, so no flips are needed.

Constraints

  • 2 <= password.length <= 10^5
  • The length of password is even.
  • password contains only 0 and 1.

More JP Morgan Chase problems

  • Longest Consecutive SequencePHONE SCREEN · Seen Nov 2026
  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU CacheONSITE INTERVIEW · Seen Nov 2026
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public int getMinFlips(String password) {
        // Write your code here.
    }
}
Checking account…