Place one delivery center to minimize the worst Chebyshev distance
Company: Amazon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Overview: Minimize a delivery grid’s worst nearest-center distance by adding at most one center. Use Chebyshev geometry and handle grids with no centers, remaining demand cells, and the zero-inconvenience boundary.
Read the full Amazon Software Engineer interview experience this question came from
Constraints
- The grid has between 1 and 300 rows and between 1 and 300 columns.
- Every row has the same length and every cell is 0 or 1.
- Distances are nonnegative integers at most 299 after a center exists.
Examples
Input: ([[0, 0, 0]],)
Expected Output: 1
Explanation: A midpoint center serves both ends of an empty row.
Input: ([[1, 0], [0, 0]],)
Expected Output: 1
Explanation: Diagonal distance is one, and one conversion cannot cover three zero cells at radius zero.
Hints
- At a fixed proposed radius, focus on cells the existing centers do not already serve.
- A Chebyshev distance bound gives an independent permitted range for each coordinate.