Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Parallel Courses (Minimum Semesters)

There are n courses. Each relation 'a b' means course a must be taken before course b. You can take any number of courses per semester as long as their prerequisites were completed in earlier semesters. Print the minimum number of semesters to finish all courses, or -1 if impossible.

Constraints

1 <= n <= 5000 0 <= m <= 5000

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.