Problem
There are n courses. Given prerequisites as pairs [a, b] meaning b must be taken before a, determine if it is possible to finish all courses (i.e. no cycle exists).
References
Difficulty
🟡 Medium
Companies
Amazon, Google, Goldman Sachs
Notes
Language: Java
Topological sort / cycle detection in directed graph. BFS (Kahn's algorithm using in-degree) or DFS with three-state coloring (unvisited/visiting/visited).
Problem
There are n courses. Given prerequisites as pairs [a, b] meaning b must be taken before a, determine if it is possible to finish all courses (i.e. no cycle exists).
References
Difficulty
🟡 Medium
Companies
Amazon, Google, Goldman Sachs
Notes
Language: Java
Topological sort / cycle detection in directed graph. BFS (Kahn's algorithm using in-degree) or DFS with three-state coloring (unvisited/visiting/visited).