Minimize flips required to make all shortest paths from top | C # program for the above approach ; Function to count the minimum number of flips required ; Dimensions of matrix ; Stores the count the flips ; Check if element is same or not ; Return the readonly count ; Driver Code ; Given Matrix ; Given path as a string ; Function call
using System ; class GFG { static int minFlips ( int [ , ] mat , String s ) { int N = mat . GetLength ( 0 ) ; int M = mat . GetLength ( 1 ) ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( mat [ i , j ] != s [ i + j ] - '0' ) { count ++ ; } } } return count ; } public static void Main ( String [ ] args ) { int [ , ] mat = { { 1 , 0 , 1 } , { 0 , 1 , 1 } , { 0 , 0 , 0 } } ; String s = "10001" ; Console . Write ( minFlips ( mat , s ) ) ; } }