Course Schedule
Problem Statement
Given a list of courses with their corresponding prerequisites, determine whether it is possible to finish all courses successfully. A student can only take at most one course at a time, and must complete the prerequisites for a course before taking it.
Input Description
- : The total number of courses.
- : A 2D array representing the prerequisites for each course. The -th entry denotes that course is a prerequisite for course .
Output Description
- A boolean value indicating whether it is possible to finish all courses successfully.
Rules and Constraints
- You should not use any built-in graph library functions.
- The graph should be directed, and its vertices and edges will not contain self-loops. However, there may be multiple edges between two vertices (i.e., multiple prerequisites for a course).
- You can have at most vertices in the graph, and the number of edges will not exceed
numCourses * (numCourses - 1)
.
- The input graph is guaranteed to be strongly connected if the result is possible, implying that there is a valid ordering if the graph has a sink vertex.
Example
Input: {"input_data":[1,2,3]}
Output: [1,2,3]