Check if There is a Valid Path in a Grid