Deviopath › JavaScript

Shortest Path in a Grid

Hard · Graphs

The grid is an array of strings. "S" is the start, "E" is the end, "." is open floor and "#" is a wall. Each step moves one cell up, down, left or right, never into a wall or outside the grid.

Write a function shortestPath that returns the minimum number of steps from S to E, or -1 if E cannot be reached. Hint: breadth-first search.

Next: Task Order (Topological Sort)