1136. Parallel Courses

Given n courses labeled from 1 to n and an array of prerequisite pairs relations where relations[i] = [prevCourse, nextCourse] indicates that prevCourse must be taken before nextCourse.

In one semester, you can take any number of courses as long as you have taken all the prerequisites in the previous semesters for the courses you are taking. Return the minimum number of semesters needed to take all courses. If there is no way to take all the courses, return -1.

Examples
Input: [3,[[1,3],[2,3]]]
Output: 2
Hints
Related Problems

1136. Parallel Courses

Given `n` courses labeled from `1` to `n` and an array of prerequisite pairs `relations` where `relations[i] = [prevCourse, nextCourse]` indicates that `prevCourse` must be taken before `nextCourse`.