You have a binary matrix where each cell is either or . For each cell, find the distance to the nearest .
The distance between two adjacent cells is . You can only move up, down, left, or right.
Return a matrix of the same size where each cell contains the distance to the nearest .
This is another multi-source BFS problem. Instead of spreading from one source, you spread from all cells at once. Before reading on, think: why start from cells instead of cells? What would happen if you ran BFS from each cell individually?