Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Course Schedule - Find Possibility and Print Roadmap



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Course Completion Feasibility

Course Completion Feasibility

Problem Statement

You have m courses labeled from 0 to m-1 that you need to complete.

Certain courses require completing other courses first. For instance, to enroll in course 3, you might need to have finished course 2, represented as a pair: [3,2].

Given the total number of courses and a list of prerequisite pairs, determine if it's possible to finish all the courses.

Examples

Example 1:

Courses: 3
Prerequisites: [[2,1]]
Output: true
Explanation: 
To take course 2, you must have completed course 1 first. Since course 1 has no prerequisites, all courses can be finished.
    

Example 2:

Courses: 3
Prerequisites: [[1,0],[0,2],[2,1]]
Output: false
Explanation:
There's a circular dependency: course 1 requires course 0, course 0 requires course 2, and course 2 requires course 1. Therefore, it's impossible to finish all courses.
    

Constraints

  • 1 ≤ m ≤ 1500
  • Prerequisite pairs length does not exceed 10000
  • No duplicate prerequisite pairs