FunctionRacerProblemsRace

Maze Escape

MediumRecursionPython, JavaScript, TypeScript, Java, C++

maze is a list of equal-length strings in which . is an open cell and # is a wall. You start in the top-left cell and want to reach the bottom-right cell by moving up, down, left or right one cell at a time, never entering a wall and never leaving the grid. Return True if the bottom-right cell can be reached and False otherwise. If the start or the goal is a wall the answer is False; a maze whose only cell is open is escaped at once.

For example, ["..#", "#.#", "#.."] can be escaped by going right, down, down, right.

Example 1

maze ["..#","#.#","#.."]
returns true

The open cells form a path from the top-left corner to the bottom-right corner.

Example 2

maze ["..#","##.","..."]
returns false

The bottom row is open but nothing open connects it to the start.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Recursion problems