This question evaluates a candidate's competence in graph traversal, shortest-path computation, and reachability analysis on grid-based representations.
You are given a 2D floor plan grid. Each cell is one of:
.
empty space (walkable)
#
wall/blocked (not walkable)
P
a person
E
an exit
A person can move 1 step per minute to the 4-neighbors (up/down/left/right) through walkable cells. Multiple people can occupy the same cell at the same time (ignore collisions).
Task:
If some person cannot reach any exit, return -1.
Explain an algorithm and its time/space complexity.