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
n = 3 NEW_LINE m = 3 NEW_LINE def countDecrements ( arr ) : NEW_LINE INDENT count_1 = 0 NEW_LINE count_2 = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( m ) : NEW_LINE INDENT if ( ( i + j ) % 2 == arr [ i ] [ j ] % 2 ) : NEW_LINE INDENT count_1 += 1 NEW_LINE DEDENT if ( 1 - ( i + j ) % 2 == arr [ i ] [ j ] % 2 ) : NEW_LINE INDENT count_2 += 1 NEW_LINE DEDENT DEDENT DEDENT print ( min ( count_1 , count_2 ) ) NEW_LINE DEDENT arr = [ [ 1 , 2 , 3 ] , [ 1 , 2 , 3 ] , [ 1 , 2 , 3 ] ] NEW_LINE countDecrements ( arr ) NEW_LINE