You are given n courses labeled 1..n and a list of prerequisite relations prereq, where each element is a pair [a, b] meaning you must complete course a before taking course b.
Return the minimum number of semesters needed to complete all courses if you may take any number of courses per semester, as long as prerequisites are satisfied.
-1
.
Input
n
prereq: List[List[int]]
Output
-1
Constraints (reasonable interview constraints)
1 <= n <= 10^5
0 <= prereq.length <= 2*10^5
1..n
Now you may take at most k courses per semester.
Return the minimum number of semesters needed to complete all courses under this constraint, or -1 if impossible.
Additional input
k
with
1 <= k <= n
Notes