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