18. Eventual Safe States Code
Medium

Problem Statement

Return an array containing all the safe nodes of a directed graph. The answer should be sorted in ascending order.

Examples

1Example 1
Input:
{ "V": 7, "adj": [ [ 1, 2 ], [ 2, 3 ], [ 5 ], [ 0 ], [ 5 ], [], [] ] }
Output:
[ 2, 4, 5, 6 ]
2Example 2
Input:
{ "V": 4, "adj": [ [ 1, 2 ], [ 2, 3 ], [ 3 ], [] ] }
Output:
[ 0, 1, 2, 3 ]
3Example 3
Input:
{ "V": 3, "adj": [ [ 1 ], [ 2 ], [ 0 ] ] }
Output:
[]
Loading...

Sign in to Run Code and Submit