Function checks if a cell is valid i . e it is inside the grid and equal to the key
internal static bool is_valid ( int x , int y , int key , int [ ] [ ] input ) { if ( x < n && y < m && x >= 0 && y >= 0 ) { if ( visited [ x ] [ y ] == 0 && input [ x ] [ y ] == key ) { return true ; } else { return false ; } } else { return false ; } }