flips
to keep track of the number of flips made so far.n - k
(inclusive), where n
is the length of the array.k
starting from the current index.k
, if we encounter an element greater than 1, decrement flips
and restore the element by subtracting 2.k
elements of the array, it's impossible to flip it, so return -1.