Your question is BFS Shortest Path in Python. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Apple Maps represents a simplified walking area as a rectangular grid. Each cell contains 0 for walkable terrain or 1 for a blocked area. Given a start cell and destination cell, return the shortest path between them using four-directional movement: up, down, left, or right.
The returned path must include both the start and destination coordinates. If multiple shortest paths exist, return any one of them. If the destination cannot be reached, return an empty list.
Implement shortest_path(grid, start, destination), where grid is a non-empty list of equal-length lists containing integers, and start and destination are coordinate lists [row, column]. Return a list of coordinate lists in traversal order, or [] when no route exists.
def shortest_path(grid, start, destination):