Depth-First Search

Explore as deep as possible, then backtrack. LC 200, 695, 79, 130.

Unvisited
Current
Backtracking
Visited

Controls

Click cells to toggle walls.

Time: O(V+E) | Space: O(V)

Stack