Function to find whether the move is valid or not
static boolean isValid ( int grid [ ] [ ] , int i , int j ) { if ( i < 0 j < 0 j >= col i >= row grid [ i ] [ j ] != 0 visited [ i ] [ j ] != 0 ) return false ; return true ; }