Reference no: EM133677480
Question: Given an array of binary digits, 0 and 1, sort the array so that all zeros are at one end and all ones are at the other. Which end does not matter.
To sort the array, swap any two adjacent elements.
Determine the minimum number of swaps to sort the array.
Example
arr=[0,1,0,1]
output=1
With 1 move, switching elements 1 and 2, yields [0,0,1,1], a sorted array.
second example arr=[0,0,1,1]
output = 0
Us ecobol ACCEPT VERB for receiving values and size of array.
input format:-
4 - array size
0
1
0
1
Constraints
1 ≤ n ≤ 105
arr[i] is in the set {0,1}