dsa10 min read
Walls and Gates — Multi-Source BFS Every FAANG Grid Interview Tests
LC 286 Walls and Gates asks you to fill each empty room with its distance to the nearest gate. The key insight is to flip the direction: instead of BFS from every room, do multi-source BFS from all gates simultaneously and push distances outward in O(m*n) time.
Read →