At Dropbox, services are modeled as an unweighted graph. Given a graph, a start node, and a target node, return one valid path from start to target.
If no path exists, return an empty list. The graph is represented as an adjacency list, where each key is a node and its value is a list of neighboring nodes.
graph: dict mapping node IDs to lists of neighboring node IDsstart: starting node IDtarget: destination node IDstart to target, inclusive[] if no path existsExample 1
graph = {'A': ['B', 'C'], 'B': ['D'], 'C': [], 'D': []}, start = 'A', target = 'D'['A', 'B', 'D']A, we can reach D through B.Example 2
graph = {1: [2], 2: [3], 3: [], 4: []}, start = 1, target = 4[]4 is disconnected from the component containing 1.1 <= number of nodes <= 10^40 <= number of edges <= 2 * 10^4