text: Minimum flips required to convert given string into concatenation of equal substrings of length K | C # program to implement the above approach ; Function that returns the minimum number of flips to convert the s into a concatenation of K - length sub - string ; Stores the result ; Iterate through string index ; Stores count of 0 s & 1 s ; Iterate making K jumps ; Count 0 's ; Count 1 's ; Add minimum flips for index i ; Return minimum number of flips ; Driver Code
code: using System ; class GFG { public static int minOperations ( String S , int K ) { int ans = 0 ; for ( int i = 0 ; i < K ; i ++ ) { int zero = 0 , one = 0 ; for ( int j = i ; j < S . Length ; j += K ) { if ( S [ j ] == '0' ) zero ++ ; else one ++ ; } ans += Math . Min ( zero , one ) ; } return ans ; } public static void Main ( String [ ] args ) { String S = "110100101" ; int K = 3 ; Console . WriteLine ( minOperations ( S , K ) ) ; } }