Difficulty: Medium | Category: Graph | Asked at: Google, Meta, Amazon | Platform: Unfoldd Arena
Solve Course Schedule II online for free in Python, JavaScript, Java, C++, TypeScript, Go, Rust, PHP, Swift, Kotlin, Dart, Ruby, C, and C#. Practice Medium level coding interview problems with instant test case evaluation and AI-powered analysis.
Keywords: Course Schedule II solution, Course Schedule II leetcode, Course Schedule II python, Course Schedule II javascript,Course Schedule II java, Course Schedule II approach, how to solve Course Schedule II, medium coding problems, Graph problems, coding interview preparation, DSA practice free.
Given a schedule of courses with their prerequisites, return the order in which they can be finished. If a valid order exists, you must return the correct order; otherwise, return an empty array.
Each course is represented as
(course, prerequisites)(course, prerequisites[i])courseprerequisites[i]This problem is a variation of the Topological Sort problem. However, in this case, if there's a cycle in the graph, we should return an empty array, as a valid order may not exist.
1 <= course1.length == course2.length <= 200 <= prerequisite <= course.length - 1courseprerequisitesInput: {"input_data":[1,2,3]} Output: [1,2,3]
Solve problems, verify your skills, and earn XP.