23. Topological Sort Using DFS
Medium

Problem Statement

Given a Directed Acyclic Graph (DAG), return the topological sort of the graph using Depth First Search (DFS).

Examples

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

Sign in to Run Code and Submit