25. Course Schedule II Code
Medium

Problem Statement

Return the ordering of courses you should take to finish all courses. If it is impossible to finish all courses (cycle exists), return an empty array.

Examples

1Example 1
Input:
{ "numCourses": 2, "prerequisites": [ [ 1, 0 ] ] }
Output:
[ 0, 1 ]
2Example 2
Input:
{ "numCourses": 4, "prerequisites": [ [ 1, 0 ], [ 2, 0 ], [ 3, 1 ], [ 3, 2 ] ] }
Output:
[ 0, 1, 2, 3 ]
3Example 3
Input:
{ "numCourses": 2, "prerequisites": [ [ 1, 0 ], [ 0, 1 ] ] }
Output:
[]
Loading...

Sign in to Run Code and Submit

    25. Course Schedule II Code – DSA Problem Solution | DSAPrime