22. Topological Sort Using BFS Code
Medium

Problem Statement

Given a Directed Acyclic Graph (DAG) with V vertices and E edges, find any Topological Sorting of that Graph using Breadth-First Search (Kahn's Algorithm).

Examples

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

Sign in to Run Code and Submit