Minimize flips required to make all shortest paths from top | 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 final count ; Given Matrix ; Given path as a string ; Function Call
function minFlips ( mat , s ) { let N = mat . length ; let M = mat [ 0 ] . length ; let count = 0 ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] != s [ ( i + j ) ] - ' ' ) { count ++ ; } } } return count ; } let mat = [ [ 1 , 0 , 1 ] , [ 0 , 1 , 1 ] , [ 0 , 0 , 0 ] ] ; let s = " " ; document . write ( minFlips ( mat , s ) ) ;