Amazon Interview Question

Topo sort (look it up on leetcode)