There are num_courses courses, numbered 0 to num_courses - 1. You get an array prerequisites of pairs [a, b], each meaning that course b has to be finished before course a can start. Return true if there is an order in which you can finish every course, and false if there is not.
Think of each pair as an arrow from b to a. The courses can all be finished exactly when those arrows never form a loop: a loop means each course on it waits for another one on it, so none of them can ever start. A pair [a, a], a course that needs itself, is the smallest loop. The same pair may appear more than once, which changes nothing. With no pairs at all, every course can be taken in any order, so the answer is true.