Bloomberg Interview Question

In a Directed Acyclic Graph print out all the paths from a source node to a target node

Interview Answer

Anonymous

Oct 20, 2018

Traverse the DAG using DFS starting from the source node. Each time you enter a node, you add it to the list, each time you exit the node you remove it from the list. When you reach the target node, print all the items currently in the list and break the recursive calls to its children.