Given numCourses courses and a list of prerequisite pairs, return a valid ordering of all courses that satisfies every prerequisite, or an empty array if no valid ordering exists (i.e., the prerequisites contain a cycle).
numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]][0,1,2,3]Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →A graph models relationships as nodes and edges, which can be directed or undirected, weighted or not. Most graph problems come down to choosing the right traversal — DFS, BFS, or union-find — for what you're trying to find.
Original problem on LeetCode ↗