490. The Maze

Practice The Maze for free on NudgeCode: Medium, Graph pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

maze is a grid where 0 is an empty cell and 1 is a wall; everything outside the grid counts as wall too. A ball sits at start. You can push it up, down, left or right. Once pushed, it keeps rolling in that direction until the next cell is a wall, and only then stops. After it stops you may push it again in any direction.

Return true if the ball can stop at destination. Rolling over destination without stopping there does not count. start and destination are [row, col] pairs.

Example

maze = [[0,0,1,0,0],
        [0,0,0,0,0],
        [0,0,0,1,0],
        [1,1,0,1,1],
        [0,0,0,0,0]]
start = [0,4], destination = [4,4]  ->  true
start = [0,4], destination = [3,2]  ->  false

In the second case the ball can roll through [3,2], but there is never a wall right after it in the direction of travel, so it can't stop there.

Constraints