Given grid dimensions rows and cols, a cell (r, c) and a distance d, build a rows x cols grid
of 0s and 1s where a cell holds 1 exactly when its Manhattan distance to (r, c) is at most d.
The Manhattan distance between (r1, c1) and (r2, c2) is |r1 - r2| + |c1 - c2|.
Examples
Input: rows = 3, cols = 4, r = 1, c = 1, d = 1
Output: [[0, 1, 0, 0],
[1, 1, 1, 0],
[0, 1, 0, 0]]
Input: rows = 2, cols = 2, r = 0, c = 0, d = 0
Output: [[1, 0],
[0, 0]]
Constraints
1 <= rows, cols <= 100,0 <= r < rows,0 <= c < cols,0 <= d <= 200
Goals
- Compute Manhattan distance between two cells
- Build a grid from a rule instead of an input grid