s
by concatenating it with itself.diff0
and diff1
, to track the number of flips required to match the alternating patterns starting with '0' and '1', respectively.minFlips
to keep track of the minimum flips encountered.diff0
or diff1
if the character does not match the expected value in the alternating patterns.diff0
or diff1
for the character that is exiting the window.minFlips
with the minimum of diff0
and diff1
after the window has reached the original string's length.minFlips
as the result.