The value needs to be opposite of the first subarray
if ( a [ curr_index ] == 0 ) count_zero ++ ; else count_one ++ ; } curr_index = curr_index + k ; segment ++ ; } ans += min ( count_one , count_zero ) ; if ( count_one < count_zero ) set = ! set ;