Minimum removals required to place all 0 s before 1 s in a Binary String | C # program for above approach ; Function to count minimum removals required to arrange all 0 s before 1 s ; Count the occurences of 0 in s ; Size of the string ; Stores the minimum number of removals required ; Iterate over each of the characters in the string s ; If the i - th character is found to be '0' ; Store the minimum of res and right_0 + left_1 in res ; Return the final result ; Driver code
using System ; using System . Collections . Generic ; public class GFG { static int minimumDeletions ( string s ) { int right_0 = ( int ) s . Split ( '0' ) . Length - 1 ; int left_1 = 0 ; int n = s . Length ; int res = Int32 . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == '0' ) { right_0 -= 1 ; } else { left_1 += 1 ; } res = Math . Min ( res , right_0 + left_1 ) ; } return res ; } public static void Main ( String [ ] args ) { string s = "001101" ; int count = minimumDeletions ( s ) ; Console . WriteLine ( count ) ; } }