Store the frequency of the four cells
if ( mp . containsKey ( mat [ i ] [ M - 1 - j ] ) ) { mp . put ( mat [ i ] [ M - 1 - j ] , mp . get ( mat [ i ] [ M - 1 - j ] ) + 1 ) ; } else { mp . put ( mat [ i ] [ M - 1 - j ] , 1 ) ; } if ( mp . containsKey ( mat [ i ] [ j ] ) ) { mp . put ( mat [ i ] [ j ] , mp . get ( mat [ i ] [ j ] ) + 1 ) ; } else { mp . put ( mat [ i ] [ j ] , 1 ) ; } if ( mp . containsKey ( mat [ N - 1 - i ] [ M - 1 - j ] ) ) { mp . put ( mat [ N - 1 - i ] [ M - 1 - j ] , mp . get ( mat [ N - 1 - i ] [ M - 1 - j ] ) + 1 ) ; } else { mp . put ( mat [ N - 1 - i ] [ M - 1 - j ] , 1 ) ; } if ( mp . containsKey ( mat [ N - 1 - i ] [ j ] ) ) { mp . put ( mat [ N - 1 - i ] [ j ] , mp . get ( mat [ N - 1 - i ] [ j ] ) + 1 ) ; } else { mp . put ( mat [ N - 1 - i ] [ j ] , 1 ) ; } x = 0 ;