LC: The Maze - spiralgo/algorithms GitHub Wiki
The Essence:
Instead of thinking individual grid tiles as node, the problem-solver is ought to think about the individual stops where the ball slides off and stops, as the vertices of the graph created by the maze.
Thus, a traversal algorithm should not start moving to other directions from tiles that are not stable.
Details:
Both BFS and DFS can be used to solve this problem. As pointed above, while traversing tiles, empty ones should be skipped in the direction currently came from. For this, simple while loops with checks can be used.
The implementation can be found here: https://github.com/spiralgo/algorithms/tree/master/src/main/java/algorithms/curated170/medium/maze