Amazon interview question

Topological Sorting