FunctionRacerProblemsRace

Distance From a Cell

MediumNumPyPython

Return a 2-D array with rows rows and cols columns where every cell holds the number of steps needed to walk to it from the cell (r, c) moving only up, down, left or right. That is |i - r| + |j - c| for the cell at row i, column j.

Example 1

rows 2
cols 3
r 0
c 1
returns [[1,0,1],[2,1,2]]

Row 0 is [1, 0, 1] and row 1 is [2, 1, 2].

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More NumPy problems