Your question is Grid Routing With Dijkstra or A*. 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.
A Dataiku DSS plugin represents a routing surface as a rectangular grid. Each cell contains -1 for an obstacle or a positive traversal cost. Given a start and goal cell, return an optimal route that minimizes the sum of costs for entered cells.
You may move up, down, left, or right. Diagonal movement is not allowed. The start cell contributes zero cost because the route begins there. Return an ordered list of [row, column] coordinates, including both endpoints. If the goal is unreachable, return an empty list.
Implement optimal_route(grid, start, goal) using Dijkstra's algorithm. An A* implementation with an admissible heuristic is an acceptable alternative.
grid is a non-empty rectangular list of lists of integers.start and goal are two-element coordinate lists [row, column].1 through 9; -1 represents an obstacle.[] when no route exists.def optimal_route(grid, start, goal):