Solving Find Eventual Safe States in go. Please try yourself first to solve the problem and submit your implementation to LeetCode before looking into solution.

Problem Description

In a directed graph, we start at some node and every turn, walk along a directed edge of the graph. If we reach a node that is terminal (that is, it has no outgoing directed edges), we stop.

Which nodes are eventually safe? Return them as an array in sorted order.

Input: graph = [[1,2],[2,3],[5],[0],[5],[],[]]
Output: [2,4,5,6]
Here is a diagram of the above graph.


See the full details of the problem Find Eventual Safe States at LeetCode

Originally posted at: