Kahn's peel-off algorithm to find a topological order.

Possibly one of my favorites, due to its simplicity.

If you just recall the visual of peeling nodes without incoming edges off the graph, the implementation follows naturally.

The data structures that we need are exactly what you'd expect:
1. Since we need to peel off nodes without incoming edges, we need a list to store such nodes.
2. Since we need to update the in-degree of nodes, we need a map from nodes to their in-degrees.

Bonus: Detecting cycles is also easy. There's one if we can't peel off all the nodes.