Minimum decrements required to make all pairs of adjacent matrix elements distinct | Function to count minimum number of operations required ; Case 1 : ; Case 2 : ; Print the minimum number of operations required ; The given matrix ; Function Call to count the minimum number of decrements required
const n = 3 ; const m = 3 ; function countDecrements ( arr ) { let count_1 = 0 ; let count_2 = 0 ; for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { if ( ( i + j ) % 2 == arr [ i ] [ j ] % 2 ) count_1 ++ ; if ( 1 - ( i + j ) % 2 == arr [ i ] [ j ] % 2 ) count_2 ++ ; } } document . write ( Math . min ( count_1 , count_2 ) ) ; } let arr = [ [ 1 , 2 , 3 ] , [ 1 , 2 , 3 ] , [ 1 , 2 , 3 ] ] ; countDecrements ( arr ) ;