Quick note: This problem is not ready for practice yet. I'll come back and work on it later. Have a lovely day! 🐥
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.
grid = [[0,0,0,1],[0,0,0,1]] return = 1
Given 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 |
1 <= n, m <= 3000 <= grid[i][j] <= 1
Updated on June 27, 2026: today's source lists the grid size limit as 300, so I updated this constraint to match it. 🐣
- Minimum Operations to Make the Integer ZeroSeen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA · Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Drone Delivery RouteOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Minimum Operations to Make Array ValidOA · Seen Jun 2026
- Sort Bug Report FrequenciesOA · Seen Jun 2026
public int minimizeInconvenience(int[][] grid) {
// write your code here
}