Add One Delivery Source

Asked at Amazon

Reported by the problem's creator, not verified

Import another question

A binary grid marks delivery points: a cell holding 1 is a source, a cell holding 0 is an ordinary cell. Movement is allowed in all eight directions (horizontal, vertical and diagonal) and every step costs 1, so the distance between (r1, c1) and (r2, c2) is max(abs(r1 - r2), abs(c1 - c2)).

The inconvenience of a cell is its distance to the nearest source. The inconvenience of the grid is the largest inconvenience over all cells.

Examples

  1. Example 1

    Input: grid = [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]

    Output: 5

    Explanation: The grid has no source, so the new one is the only one. Placing it in column 4 or 5 of the middle row leaves the farthest column 5 steps away and every row within 1, so the best possible inconvenience is 5.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.