Minimum Grid Inconvenience
Problem statement
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.
Examples
Example 1
grid = [[0,0,0,0],[0,0,0,0],[0,0,0,0]]return = 2With no existing delivery center, it is optimal to convert the center cell (1,1) to 1. The farthest cells then have distance 2.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 1 more worked example, explained
- Guided hints and editorial
- Run your code on real test cases
Pro subscription, billed yearly — or $19 month-to-month. Cancel anytime.