Function to check if all elements present in descending diagonal starting from position ( i , j ) in the matrix are all same or not
function checkDiagonal ( mat , i , j ) { let res = mat [ i ] [ j ] ; while ( ++ i < N && ++ j < M ) {