Given numCourses and prerequisites [a,b] meaning 'must take b before a', determine if you can finish all courses. This is cycle detection in a directed graph.
Use DFS with 3 states: unvisited, in-progress (currently in DFS path), visited (done). If we revisit an in-progress node, there's a cycle.
💡 Pro tip: Understand this problem deeply — don't just memorize the code. Try explaining the approach out loud as if teaching a friend. If you can explain it simply, you truly understand it!
canFinish(4, [[1,0],[2,0],[3,1],[3,2]])
True
canFinish(2, [[1,0],[0,1]])
False