BFS was the obvious move and I got there fast, but I fumbled a bit when they asked about directed vs undirected.
Start by clarifying the problem constraints (e.g., edge weights, graph representation) and then propose BFS for unweighted graphs or Dijkstra for weighted graphs, treating blocked nodes as removed. Walk through the algorithm step-by-step, analyze time and space complexity, and discuss how the approach adapts for directed vs. undirected graphs.
Pro tip: Explicitly state your assumptions about edge weights and graph representation before diving into the algorithm; this shows you think about problem constraints and avoids misunderstandings. Also, mention that blocked nodes are skipped during traversal, and unreachable nodes return -1.
Ask about edge weights (unweighted vs. weighted), graph representation (adjacency list/matrix), and whether blocked nodes are given as a list or marked in the graph. Confirm that blocked nodes should be excluded from traversal and return -1.
For unweighted graphs, use BFS from the source; for weighted graphs with non-negative weights, use Dijkstra's algorithm. Mention that if negative weights exist, Bellman-Ford is needed, but typically not expected here.
Explain initialization: distance array with infinity, source distance 0, and a queue (BFS) or priority queue (Dijkstra). Describe how to skip blocked nodes and update distances for neighbors.
For BFS: O(V+E) time, O(V) space. For Dijkstra with binary heap: O((V+E) log V) time, O(V) space. Mention that blocked nodes are simply not processed, so they don't affect complexity.
For undirected graphs, treat each edge as bidirectional; for directed graphs, only follow outgoing edges. The core algorithm remains the same, but adjacency list construction differs.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.