Back to problems

Minimize the Maximum Distance to a 1 After Flipping One 0

Algorithm · Amazon · Hard

Problem: Reduce the Maximum Distance to a 1 by Flipping at Most One 0 You are given a binary matrix grid with m rows and n columns; every entry is either 0 or 1. You can select no more than one cell containing 0 and replace its value with 1. For every 0 that remains, define its distance as the Manhattan distance to the closest 1 in the matrix. Movement is limited to the four neighboring directions—up, down, left, and right—and each move contributes 1 to the distance. Return…

Checking your access…