Minimum Grid Inconvenience
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt at this Amazon OA, reported in August 2026, is trying every 0 cell as the new center and rerunning a search each time. On a 500 by 500 grid that's hopeless. The problem is a grid with delivery centers, Chebyshev distance, and one free conversion to minimize the worst-case distance. It's a multi-source BFS plus a binary search on the answer. If you blank on the structure during the live assessment, StealthCoder is the safety net that reads the problem and hands you a working approach quietly.
The problem
A city is represented by a binary grid. A cell marked 1 is a delivery center, and a cell marked 0 is any other place. The distance between two cells is the maximum of the absolute row-coordinate difference and the absolute column-coordinate difference. The inconvenience of the grid is the maximum, over every 0 cell, of its distance to the nearest delivery center. Amazon may open one new delivery center by converting at most one 0 cell into 1. Return the minimum possible inconvenience after this conversion. Function getMinInconvenience(grid: int[][]) → int Examples Example 1 grid = [[0,0,0,0],[0,0,0,0],[0,0,0,0]] return = 2 With no existing delivery center, it is optimal to convert the center cell (1,1) to 1. The farthest cells then have distance 2. Example 2 grid = [[0]] return = 0 Convert the only cell to a delivery center, leaving no 0 cell with positive distance. Constraints 1 <= n, m <= 500 0 <= grid[i][j] <= 1
Reported by candidates. Source: FastPrep
Pattern and pitfall
Start with multi-source BFS from all existing 1 cells. With Chebyshev distance, you expand over all 8 neighbors. That gives each cell its nearest-center distance. Now binary search the answer D. A cell is already fine if its distance is at most D. Collect the cells with distance greater than D. One new center must cover all of them, so it must lie within D of each in both row and column. Track the min and max of row and column over the bad cells, and also the max of (r+c) style bounds isn't needed because Chebyshev is axis-separable. Check if a cell exists in the intersection of the ranges. Since you can convert any 0 cell, and bounds are within the grid, that's an O(1) check per D. The pitfall is the empty-center case, where BFS has no sources and every cell is infinite. Handle it by treating all cells as bad. Also, if there are no bad cells, the answer is 0 or the current max. Use Manhattan by mistake and you fail example 1.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Minimum Grid Inconvenience cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Grid Inconvenience FAQ
What's the trick in Minimum Grid Inconvenience?+
Run multi-source BFS with 8-direction moves to get each cell's distance to the nearest center. Then binary search the inconvenience D and check whether one new center can cover every cell whose distance exceeds D. Chebyshev distance makes the coverage check a simple rectangle intersection.
How do I handle a grid with no delivery centers?+
BFS has no sources, so every cell is uncovered. Treat all cells as bad when checking a candidate D. Example 1 shows it: a 3 by 4 grid answers 2, since the center cell reaches everything within distance 2. A 1 by 1 grid answers 0.
Why does the distance use max instead of Manhattan?+
The problem defines distance as the max of row and column differences, called Chebyshev distance. That means BFS expands through all 8 neighbors at cost 1. It also lets you test coverage by independent row and column ranges, which is what makes the check fast.
How hard is this one really?+
Medium-hard. BFS alone is easy, but combining it with binary search and the rectangle coverage check is where people stall. With n and m up to 500, you need roughly O(nm log(nm)) total. Brute force over every conversion candidate times a BFS will time out.
How do I prepare in 48 hours?+
Write multi-source BFS from memory on a grid with 8 directions. Then practice binary search on the answer with a feasibility check. Test edge cases: a single cell, all zeros, all ones, and one center in a corner. That covers most of what this problem tests.