Amazon interview question

Topo sort (look it up on leetcode)