Google·Software Engineer·Technical Phone Screen
- Given a 2D grid with possible obstacles, implement a shortest-path search from a start cell to a target cell using BFS. Alternatively, count the number of connected regions in the grid.
- How would you extend this to a 3D grid? Walk through the state representation and how complexity changes.
- Why use BFS here instead of DFS or other search strategies? When would you prefer one over the other?
“Got the BFS skeleton down pretty fast, 4-directional moves, visited set, queue.”