Compute shortest paths with blocked nodes
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
Quick Answer: This question evaluates proficiency with graph algorithms, shortest-path and reachability concepts when nodes are removed or blocked, and the ability to analyze time and space complexity across directed and undirected graphs.
Constraints
- Nodes are labeled 0 through n-1
- Edges are unweighted
Examples
Input: (5, [[0, 1], [1, 2], [0, 3], [3, 4]], 0, [3], False)
Expected Output: [0, 1, 2, -1, -1]
Input: (4, [[0, 1], [1, 2], [2, 3]], 0, [], True)
Expected Output: [0, 1, 2, 3]
Input: (3, [[0, 1]], 2, [2], False)
Expected Output: [-1, -1, -1]
Hints
- Treat blocked nodes as removed before BFS.
- For directed graphs, only add the given edge direction.