Mid-levelMid (3–6 yrs)CodingPythonGoogleAmazonTikTok
Course Schedule (cycle detection)
There are numCourses and prerequisites[i] = [a,b] meaning b before a. Return true if you can finish all courses.
Answers use simple, clear English.
Time: O(V+E)Space: O(V+E)
Quick interview answer
Model as directed graph; detect cycle with DFS colors (white/gray/black) or Kahn's BFS topological sort. If a cycle exists, impossible.
Detailed answer
Model as directed graph; detect cycle with DFS colors (white/gray/black) or Kahn's BFS topological sort. If a cycle exists, impossible.
midsenior#graph#topo-sort#blind75