Minimize count of flips required such that no substring of 0 s have length exceeding K | C # program to implement the above approach ; Function to return minimum number of flips required ; Base Case ; Stores the count of minimum number of flips ; Stores the count of zeros in current subString ; If current character is 0 ; Continue ongoing subString ; Start a new subString ; If k consecutive zeroes are obtained ; End segment ; Return the result ; Driver Code ; Function call
using System ; class GFG { static int min_flips ( String str , int k ) { if ( str . Length == 0 ) return 0 ; int ans = 0 ; int cnt_zeros = 0 ; foreach ( char ch in str . ToCharArray ( ) ) { if ( ch == '0' ) { ++ cnt_zeros ; } else { cnt_zeros = 0 ; } if ( cnt_zeros == k ) { ++ ans ; cnt_zeros = 0 ; } } return ans ; } public static void Main ( String [ ] args ) { String str = "11100000011" ; int k = 3 ; Console . Write ( min_flips ( str , k ) ) ; } }