Hadrian interview question

Traverse a directed acyclic graph in Python