Back to problems

Reconstruct the BFS Path Before Reaching a Target

Algorithm · Google · Medium

Shortest Path Nodes Before Target Medium · Topics · Company Tags · Hints You are given a directed graph with n nodes, labeled 0 to n-1, and a collection of directed edges. Also given are two distinct-or-equal nodes named start and target. Use Breadth‑First Search (BFS) to compute a shortest path from start to target. Output all nodes that lie on that path before reaching target — that is, the sequence from start up to and including the node immediately prior to target. If…

Checking your access…