I went straight to single-source BFS and the interviewer just kind of waited.
Model the problem as a multi-source shortest path where each torch is a source with initial power 16, and edge weights are 1. Use a modified Dijkstra or BFS with a priority queue to propagate the maximum power to each node, updating only when a higher power is found.
Pro tip: Clarify edge cases upfront: disconnected components, multiple torches on the same node, and nodes that remain unpowered. Also, mention that if all edge weights are 1, a BFS with a max-heap can be used, but Dijkstra is more general.
Restate the problem: each torch starts with power 16, power decreases by 1 per edge, and each node takes the maximum power from any path. Ask about graph size, edge weights, and whether power can be negative.
Recognize this as a multi-source shortest path with maximization. Use Dijkstra's algorithm with a max-heap, initializing all torch nodes with power 16 and others with -1 (unpowered).
Push all torches into a priority queue with their power. While the queue is not empty, pop the node with the highest power; for each neighbor, compute new power = current power - 1. If new power > existing power, update and push.
After propagation, any node with power < 0 is unpowered (set to -1 or 0 as required). Return the array of final power levels.
Time complexity is O((V+E) log V) with a binary heap. Mention that if all edges have weight 1, a BFS with a deque can achieve O(V+E) by processing in decreasing power order.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.