Coding Trainer

Course Schedule II

MediumDFSk-topological-sortLC #210

Problem

Given numCourses and prerequisites, return a valid course order to finish all courses. If impossible (cycle), return empty array.

Example: numCourses=4, prerequisites=[[1,0],[2,0],[3,1],[3,2]] → [0,2,1,3]