Problem · String

Minimum Flips to Alternate Binary String (With K Flip Window)

HardGoogleNEW GRADOA
See Google hiring insights

You are given a binary string s. In one operation, you can flip a subarray of length exactly k (flip all bits in that subarray). Return the minimum number of such operations needed to make the string alternating (i.e., no two adjacent bits are the same). If it's not possible, return -1.

Examples
01 · Example 1
s = "00010111"
k = 3
return = 2
^~^
More Google problems
drafts saved locally
public int minFlips(String s, int k) {
  // write your code here
}
s"00010111"
k3
expected2
sign in to submit