TikTok interview question

Implement topological sort given transitions