Problem
At Meta, services such as News Feed, Ads Delivery, and Graph API can depend on other internal systems. Given a directed graph of system dependencies and a starting system, implement breadth-first search (BFS) to return the order in which systems are discovered, grouped by dependency distance.
A directed edge A -> B means system A depends directly on system B. Starting from start, traverse all reachable systems using BFS. Return two results:
- The flat BFS traversal order.
- A list of levels, where each level contains systems at the same distance from
start.
Input / Output
- Input:
graph: a dictionary mapping each system name (string) to a list of directly dependent systems (list of strings)start: a string representing the starting system
- Output:
- A dictionary with keys:
order: list of strings in BFS visitation orderlevels: list of lists of strings, grouped by BFS depth
- A dictionary with keys:
Constraints
- 1 <= len(graph) <= 10^4
- 0 <= total number of edges <= 10^5
- System names are non-empty strings
- The graph may contain cycles
- start is guaranteed to be a key in graph
Function Signature
def bfs_dependencies(graph, start):
You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

