There are a total of `numCourses` courses you have to take, labeled from 0 to `numCourses - 1`. You are given an array `prerequisites` where `prerequisites[i] = [ai, bi]` indicates that you must take course `bi` first if you want to take course `ai`. Return true if you can finish all courses. Otherwise, return false.
Cycle Detection in Directed Graph (DFS)
This is a classic problem of detecting a cycle in a directed graph. We can represent the courses as nodes and prerequisites as directed edges. If the graph is a Directed Acyclic Graph (DAG), we can finish all courses. We use DFS with three states for each node: 0 (unvisited), 1 (visiting/in current recursion stack), and 2 (visited/fully processed). If we encounter a node in state 1 during DFS, a cycle exists.