My first instinct was to BFS from each person separately to find their nearest exit, then take the max.
Model the grid as a graph where each cell is a node and edges connect adjacent non-wall cells. Use multi-source BFS from all exits to compute the shortest distance from every cell to the nearest exit, then check if all people have finite distances and return the maximum distance as the minimum time for all to escape.
Pro tip: Clarify that people move independently and do not block each other, so the problem reduces to finding the maximum of individual shortest paths. Mention that if people could block, the problem becomes much harder (e.g., multi-agent pathfinding), but here it's a simple BFS.
Confirm that people can move in four directions, cannot pass through walls, and that multiple people can occupy the same cell. Discuss edge cases like no people, no exits, or unreachable people.
Represent each cell as a node with edges to adjacent non-wall cells. Use BFS because it finds shortest paths in unweighted graphs.
Initialize a queue with all exit cells at distance 0. BFS outward to compute the shortest distance from each cell to the nearest exit.
For each person, check if their distance is finite. If any is infinite, return that not all can escape. Otherwise, the answer is the maximum distance among all people.
Time and space are O(R*C) for an R x C grid. If the grid is huge, consider early termination or bidirectional BFS, but multi-source BFS is optimal here.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.