text: Minimum adjacent swaps required to Sort Binary array |  ; Driver Code
code: using System ; class GFG { static int minswaps ( int [ ] arr , int n ) { int count = 0 ; int num_unplaced_zeros = 0 ; for ( int index = n - 2 ; index >= 0 ; index -- ) { if ( arr [ index ] == 0 ) num_unplaced_zeros += 1 ; else count += num_unplaced_zeros ; } return count ; } static void Main ( ) { int [ ] arr = { 0 , 0 , 1 , 0 , 1 , 0 , 1 , 1 } ; Console . WriteLine ( minswaps ( arr , 9 ) ) ; } }