text: Maximize count of 0 s in left and 1 s in right substring by splitting given Binary string | C # program for the above approach ; Function to maximize the sum of the count of zeros and ones in the left and right substring ; To store the total ones ; Count the total numbers of ones in string str ; To store the count of zeros and ones while traversing string ; Iterate the given string and update the maximum sum ; Update the maximum Sum ; Driver Code ; Given binary string ; Function call
code: using System ; class GFG { static int maxSum ( string str ) { int maximumSum = 0 ; int totalOnes = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] == '1' ) { totalOnes ++ ; } } int zero = 0 , ones = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { if ( str [ i ] == '0' ) { zero ++ ; } else { ones ++ ; } maximumSum = Math . Max ( maximumSum , zero + ( totalOnes - ones ) ) ; } return maximumSum ; } public static void Main ( string [ ] args ) { string str = "011101" ; Console . Write ( maxSum ( str ) ) ; } }