Find Eventual Safe States
MediumLeetCodeShortest Paths & Topological Sort
Approach hintTry it first, then revealHide
A node is safe when every path from it ends at a terminal node. Reverse the edges and run Kahn's algorithm from the terminal nodes, or use a three-colour DFS that marks nodes reaching a cycle as unsafe.