Distance to Nearest Zero (01 Matrix)
Medium · Queue & Deque · about 20 minutes
Asked at Google, Amazon, Uber.
Given a binary matrix mat, return a matrix of the same size where each cell holds the distance to the nearest 0, moving up, down, left or right one step at a time. The matrix contains at least one 0.