There are num_courses courses numbered 0 to num_courses - 1. A pair [a, b] in prerequisites means you must take course b before course a. Return True if it is possible to take all the courses.
For num_courses = 2 and prerequisites = [[1, 0]] the answer is True; with [[1, 0], [0, 1]] it is False.
Example 1
Input:
can_finish(2, [[1, 0]])
Output:
True
Example 2
Input:
can_finish(2, [[1, 0], [0, 1]])
Output:
False
0 <= num_courses <= 1000000 <= len(prerequisites) <= 200000No results yet
Run your code to check it against the examples, or submit to run every test.