Approach Summary
Multi-source BFS starting from all gates (value 0) simultaneously. Empty rooms get filled with distance from nearest gate.
How to Recognize This Pattern
- "Fill each room with distance to nearest gate"
- Multi-source BFS beats repeated single-source BFS
Complexity Analysis
Time Complexity
O(m × n)
Space Complexity
O(m × n)
Tags
Array BFS Matrix