Apple Interview Question

Topological sort