Maze Path Finder

Backtracking Maze Pathfinding

Maze Path Finder

You are given a maze represented as a 2D grid of characters. Each cell in the maze can be one of the following:

  • 'S': The starting point.
  • 'E': The exit point.
  • '.': An open cell through which you can move.
  • '#': A wall which you cannot pass through.

Write a function that finds a valid path from the start ('S') to the exit ('E') using backtracking. You may move one cell at a time in the four cardinal directions (up, down, left, right). Return the path as a list (or array) of coordinates, where each coordinate is a pair of zero-indexed row and column indices. If no path exists, return an empty list.

Example:

For the maze:

S . . #
# . # .
. . . E

A possible output (one of many valid paths) could be:

[[0,0], [0,1], [0,2], [1,1], [2,1], [2,2], [2,3]]

Notes:

  • The maze will always have exactly one 'S' and one 'E'.
  • If multiple valid paths exist, you can return any one of them.
  • Feel free to structure your solution using helper functions if needed.
  • Today's challenge is inspired by the spirit of exploration and problem-solving, much like historical explorers navigating unknown paths.