Segregate 1 s and 0 s in separate halves of a Binary String | C # program for the above approach ; Function to count the minimum number of operations required to segregate all 1 s and 0 s in a binary string ; Stores the count of unequal pair of adjacent characters ; If an unequal pair of adjacent characters occurs ; For odd count ; For even count ; Driver Code ; Given string ; Length of the string ; Prints the minimum count of operations required
using System ; public class GFG { static void minOps ( String s , int N ) { int ans = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( s [ i ] != s [ i - 1 ] ) { ans ++ ; } } if ( ans % 2 == 1 ) { Console . Write ( ( ans - 1 ) / 2 ) ; return ; } Console . Write ( ans / 2 ) ; } public static void Main ( String [ ] args ) { String str = "01011100" ; int N = str . Length ; minOps ( str , N ) ; } }