Approach Summary
Multi-source BFS from all 0-cells simultaneously. Each 1-cell takes its distance from the nearest 0.
How to Recognize This Pattern
- "Distance of each cell to nearest 0"
- Multi-source BFS, not single-source
Complexity Analysis
Time Complexity
O(m × n)
Space Complexity
O(m × n)
Tags
Array BFS Matrix Dynamic Programming