DoorDash interview question

Topological sort question - just study topological sort.