Problem · Matrix

Minimum Grid Inconvenience

HardAmazonOA
See Amazon hiring insights

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.

The problem statement continues
Pro
Examples
01 · 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.

FastPrep Pro
Reported in 1 Amazon interview this week

Unlock the full problem

  • Full problem statement and constraints
  • 1 more worked example, explained
  • Guided hints and editorial
  • Run your code on real test cases
$9/month

Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

Unlock the full problem

  • Full problem statement and constraints
  • 1 more worked example, explained
  • Guided hints and editorial
  • Run your code on real test cases
$9/month

Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week