AO
Back

Add One Delivery Center to Minimize Grid Inconvenience

Also reported as getMinInconvenience

OAAsync OALast reported September 2026Medium Frequency

Problem Overview

The round: the coding half of Amazon's online assessment; the other half is an AI-assisted task in a code repository, usually debugging. Seven candidates reported this grid question between June and September 2026, five of them in August or September, and a round-up of June–September Amazon reports says several August OAs had it. Three candidates posted the prompt; two give the constraints, and one gives the function name and a second example. The examples and constraints below are as reported; the prose is paraphrased.

Problem

You are given an n × m grid where 1 is a delivery center and 0 is an empty location. The distance between cells (r1, c1) and (r2, c2) is the Chebyshev distance max(|r1 - r2|, |c1 - c2|). The grid's inconvenience is the largest distance from any 0 cell to its nearest delivery center. You may convert at most one 0 into a 1. Return the minimum possible inconvenience.

def getMinInconvenience(grid: list[list[int]]) -> int: ...

Constraints

  • 1 ≤ n, m ≤ 500
  • grid[i][j] is 0 or 1

Example 1

grid = [[0, 0, 0, 1],
        [0, 0, 0, 1]]
Distances now:        3 2 1 0 / 3 2 1 0     -> inconvenience 3
Convert (0, 0):       0 1 1 0 / 1 1 1 0     -> inconvenience 1
Output: 1

Example 2

grid = [[0, 0, 0, 0],
        [0, 0, 0, 0],
        [0, 0, 0, 0]]
Convert (1, 1); every cell is then within distance 2.
Output: 2

Reported variant: 4-direction distance. In one thread the worked example uses Manhattan distance, |r1 - r2| + |c1 - c2| (moves only up, down, left and right): [[0, 0, 0, 0], [0, 0, 0, 1]] has inconvenience 4, and converting the top-left cell brings it to 2. A reply there likens it to LeetCode 542 (01 Matrix) with one flip added and says five tests timed out. Ask which distance applies; the two give different answers on most grids. The last two tests call the variant as getMinInconvenienceManhattan(grid), same input and output.

def getMinInconvenienceManhattan(grid: list[list[int]]) -> int: ...

What Reports Emphasize

What candidates report: Three candidates posted the prompt with Chebyshev distance and a fourth describes 8-direction moves, which is the same thing; in one thread the worked example uses 4-direction (Manhattan) distance instead.; Three candidates describe a multi-source BFS for the current distances followed by a binary search on the answer; one of them checks each K by bounding the cells that are still too far.; Replies on one report say almost nobody would solve it in 40 minutes without having seen it.

Our note (not from the reports): The squares overlap exactly when the far cells' bounding box spans at most 2K rows and 2K columns. Ask which distance applies before coding.

Practice

Write your own against 8 test cases, or read the worked solution — approach, complexity, and code that runs.

Prepping for Amazon with friends?

Send them this page. It is free to read, no account needed.

More Amazon Questions

Free preview

Every question in the Amazon catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 57 Amazon questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Amazon · OA · Reported 7× across candidate reports
Is this helpful?