Given an m x n binary matrix mat, return the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1.
Example 1
Input: mat = [[0,0,0],[0,1,0],[0,0,0]]
Output: [[0,0,0],[0,1,0],[0,0,0]]
Explanation: Every cell except the center already holds 0, so its distance is 0. The center cell (1,1) touches four zeros directly, so its nearest 0 is 1 step away.
Example 2
Input: mat = [[0,0,0],[0,1,0],[1,1,1]]
Output: [[0,0,0],[0,1,0],[1,2,1]]
Explanation: The bottom row cells (2,0) and (2,2) each have a 0 directly above them, so their distance is 1. Cell (2,1) is surrounded by 1s; the closest 0 is two steps away (e.g. up twice to (0,1)), so its distance is 2.
Example 3
Input: mat = [[0]]
Output: [[0]]
Explanation: The only cell is already 0, so its distance to the nearest 0 is 0.
Start BFS from all 0-cells simultaneously. Each level adds 1 to the distance.
Run checks all cases above. Submit evaluates all test cases.