Model the problem as a multi-source shortest path on a grid, where all taxi cells are sources with distance 0. Use BFS from all taxis simultaneously to compute the shortest distance to every cell in O(m*n) time, since each edge has unit weight. Discuss the approach, then implement it cleanly with a queue and visited array.
Pro tip: Mention that BFS is optimal here because the grid is unweighted, and contrast it with running BFS from each cell (which would be O((mn)^2)). This shows you understand complexity trade-offs and can optimize early.
Ask about grid size, whether taxis are given as a list or marked in the grid, and if distance is Manhattan or path-based (with obstacles). Confirm that movement is 4-directional and that unreachable cells should be marked as -1 or infinity.
Recognize that this is a multi-source shortest path problem on an unweighted graph. BFS from all sources simultaneously is optimal, as it explores cells in increasing order of distance.
Initialize a queue with all taxi positions and set their distance to 0. Then perform BFS, updating distances for unvisited neighbors and enqueueing them.
State that time and space are O(m*n). Handle edge cases: no taxis (return -1 or infinity for all), all cells are taxis (distance 0), and obstacles if present.
Write clean code with a queue and a distance matrix. Test with a small example, including a case with unreachable cells, to verify correctness.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.