Shortest Path in a Grid

medium
Unit 14 · Strings & BFS0/3 to milestone

A warehouse robot moves up, down, left or right on a grid. # is a wall, . is open floor, S is the start and E is the exit.

Implement shortest_path(grid) for a list of equal-length strings. Return the number of moves on the shortest route from S to E, or -1 if there isn't one. Then implement shortest_route(grid) returning the list of (row, col) cells on one shortest route, from S to E inclusive, or []. When several routes tie, explore neighbours in the order up, down, left, right.

#bfs#graphs#grids2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Shortest Path in a Grid · TechGradify