Minimum number of operations required to maximize the Binary String | Function to find the number of operations required ; Swap 0 ' s ▁ and ▁ 1' s ; Return the answer ; Driver Code
function minOperation ( s , n ) { let ans = 0 ; let i = 0 , j = n - 1 ; while ( i < j ) { if ( s [ i ] == ' ' && s [ j ] == ' ' ) { ans ++ ; i ++ ; j -- ; continue ; } if ( s [ i ] == ' ' ) { i ++ ; } if ( s [ j ] == ' ' ) { j -- ; } } return ans ; } let n = 8 ; let s = " " ; document . write ( minOperation ( s , n ) ) ;