Minimum Delivery Center Inconvenience
Learn this problemProblem statement
Amazon has multiple delivery centers all over the world. A city is given in the form of a grid where the delivery centers are marked as 1 and all other places are marked as 0. Distance between two cells is defined as the maximum absolute distance between x coordinates and y coordinates. For example, distance between (1, 2) and (0, 4) is max(|1 - 0|, |2 - 4|) = 2. The inconvenience of the grid is defined as the maximal distance of any place marked 0 from its nearest delivery center.
Amazon is planning to open a new delivery center to reduce the inconvenience of the grid. Minimize the inconvenience of the grid by converting at most one 0 (any place) to 1 (a delivery center) and report this minimum value.
Many thanks to the friend who shared this new last-seen signal!Your help keeps this problem record more accurate!🦋
Function
minimizeInconvenience(grid: int[][]) → intExamples
Example 1
grid = [[0,0,0,1],[0,0,0,1]]return = 1Given n = 2 rows, m = 4 columns, and grid = [[0, 0, 0, 1], [0, 0, 0, 1]]:
| 0 | 0 | 0 | 1 |
| 0 | 0 | 0 | 1 |
Distances to nearest delivery centers are shown below. The initial inconvenience of the grid is 3.
| 3 | 2 | 1 | 0 |
| 3 | 2 | 1 | 0 |
It is optimal to convert (0, 0) to a delivery center, resulting in:
| 1 | 0 | 0 | 1 |
| 0 | 0 | 0 | 1 |
Now the inconvenience is 1, with distances as:
| 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 0 |
Constraints
1 <= n, m <= 3000 <= grid[i][j] <= 1
Updated on June 27, 2026: this constraint update is backed by the newest official source I found, which lists the grid size limit as 300. 🐣
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026