Distance to the Nearest Source
Fill a grid with each cell's distance to the nearest source, going around blocked cells.
The problem
Implement multi_source_distances(rows, columns, sources, blocked). The grid has rows x columns cells. sources and blocked are lists of [row, column] pairs; the sources are distinct and never blocked. From a cell you can move up, down, left or right into a cell that is inside the grid and not blocked. Return a rows-by-columns list of lists in which each cell holds the fewest moves needed to reach it from the nearest source (a source itself holds 0). Blocked cells, and cells that no source can reach, hold -1.
Starter code
def multi_source_distances(rows, columns, sources, blocked):
passPublic examples
rows = 3, columns = 4, sources = [[0, 0], [2, 3]], blocked = []gives[[0, 1, 2, 2], [1, 2, 2, 1], [2, 2, 1, 0]]rows = 2, columns = 3, sources = [[0, 0]], blocked = [[0, 1]]gives[[0, -1, 4], [1, 2, 3]]
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
