Problem · Matrix
Place K Buildings to Minimize Maximum Grid Distance
Learn this problemProblem statement
Consider an empty grid with rows rows and columns columns. Place exactly k buildings in distinct cells.
The distance from a cell to its closest building is the minimum Manhattan distance to any building. Return the smallest possible value of the maximum such distance over every grid cell.
Function
minimumMaximumDistance(rows: int, columns: int, k: int) → intExamples
Example 1
rows = 3columns = 3k = 1return = 2Placing the building in the center leaves every corner at Manhattan distance 2.
Example 2
rows = 2columns = 3k = 2return = 1Buildings in the middle column make every cell at most one step from a building.
Constraints
1 <= rows, columns <= 81 <= k <= rows * columns- Buildings occupy distinct cells.