Minimize flips on K |  ; We 're flipping the subarray from  A[i] to A[i+K-1] ; ' ' ▁ If ▁ we ▁ can ' t flip the entire subarray , its impossible ; Driver Code
def minKBitFlips ( A , K ) : NEW_LINE INDENT temp = [ 0 ] * len ( A ) NEW_LINE count = 0 NEW_LINE flip = 0 NEW_LINE for i in range ( len ( A ) ) : NEW_LINE INDENT flip ^= temp [ i ] NEW_LINE if ( A [ i ] == flip ) : NEW_LINE INDENT count += 1 NEW_LINE if ( i + K > len ( A ) ) : NEW_LINE INDENT return - 1 NEW_LINE DEDENT flip ^= 1 NEW_LINE if ( i + K < len ( A ) ) : NEW_LINE INDENT temp [ i + K ] ^= 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT A = [ 0 , 1 , 0 ] NEW_LINE K = 1 NEW_LINE ans = minKBitFlips ( A , K ) NEW_LINE print ( ans ) NEW_LINE