BFS was the right move and I knew that pretty quickly.
Model the businesses as nodes and relationships as undirected edges in a graph, then use BFS to find the shortest path from source to target. Reconstruct the path using parent pointers and compute the degree of separation as the number of intermediate nodes (path length minus 2).
Pro tip: Clarify edge cases upfront—like when source equals target (degree 0) or no path exists—and mention that BFS is optimal for unweighted graphs, showing you understand complexity trade-offs.
Confirm the graph is unweighted and undirected, and discuss edge cases such as source == target, disconnected nodes, and multiple shortest paths.
Explain that BFS guarantees the shortest path in an unweighted graph, with O(V+E) time and space complexity.
Use a queue for traversal and a parent map to record the predecessor of each visited node, enabling path reconstruction.
Backtrack from target to source using the parent map to build the path, then calculate degree as the number of intermediate nodes (path length minus 2).
State time and space complexity, and walk through test cases including normal, edge, and no-path scenarios.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.