Implement BFS to Find Shortest Path in Graph
Company: Amazon
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: Medium
Interview Round: Technical Screen
##### Scenario
Social network needs to compute the shortest friend-distance between two users in an undirected graph containing millions of nodes.
##### Question
Implement an iterative BFS that returns the minimum number of hops between a source and target user. Extend the function to also return one of the actual shortest paths.
##### Hints
Use a queue, visited set, and early exit when target is found.
Quick Answer: This question evaluates understanding of graph traversal algorithms, particularly breadth-first search, and competency in computing shortest paths and reconstructing an example shortest route in large undirected graphs.