Compute decayed power levels in a graph
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Onsite
Quick Answer: This question evaluates knowledge of graph algorithms and distance-based propagation, testing concepts such as shortest-path distance computation, multi-source reachability, and aggregation of maximum influences with per-edge decay.
Constraints
- 1 <= n <= 10^5
- 0 <= len(edges) <= 2 * 10^5
- 0 <= u, v < n for every edge (u, v)
- The graph is undirected and unweighted
- 0 <= len(torches) <= n, and torch indices are valid node indices
- The graph may be disconnected, and the torch list may contain duplicates
Examples
Input: (6, [(0,1), (1,2), (2,3), (3,4), (4,5)], [0])
Expected Output: [16, 15, 14, 13, 12, 11]
Explanation: Node 0 is a torch with power 16, and each step along the line decreases power by 1.
Input: (8, [(0,1), (1,2), (1,3), (3,4), (4,5), (2,6)], [5, 0])