text: Minimum adjacent swaps required to Sort Binary array |  ; Driver Code
code: function minswaps ( arr , n ) { var count = 0 ; var num_unplaced_zeros = 0 ; for ( var index = n - 1 ; index >= 0 ; index -- ) { if ( arr [ index ] == 0 ) num_unplaced_zeros += 1 ; else count += num_unplaced_zeros ; } return count ; } var arr = [ 0 , 0 , 1 , 0 , 1 , 0 , 1 , 1 ] ; document . write ( minswaps ( arr , 9 ) ) ;