I have no idea why I pass all test cases and fail on validator 3.
My current algorithm works as:
Determine total number of 1s, then go through the input, and add a swap every time a 0 is encountered within the number of 1s.
For example, let input be: 1 0 0 1 1
1s = 3
While looping, at positions 1 and 2,we encounter a 0,so I increment swaps.
∴swaps = 2
if there is anything wrong, please point it out.Any help will be appreciated