TikTok Interview Question

Like I said, a bus hop topo sort problem.