Distance From a Cell
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
1 <= rows, cols <= 8(r, c)is inside the grid
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Halfway PointMedium
- Highest Cell PositionMedium
- Matching PairsMedium
- Mean of Each GroupMedium
- Multiplication TableMedium
- Order by ScoreMedium
- Pairs Hitting TargetMedium
- Pairwise SumsMedium