Can all courses be finished given prerequisites?
Reported in Just Eat Takeaway.com European engineering loops. Topological sort and directed cycle detection interview staple.
Interview scenario
Context for Just Eat Takeaway.com candidates:
Each prerequisite pair means one course depends on another. Return whether all courses can be completed.
Model answer
Try answering aloud first
Cover trade-offs, structure, and a concrete example before revealing the baseline response.
How to frame this at Just Eat Takeaway.com: Connect your answer to measurable impact, clarity of thought, and trade-offs the team cares about. Below is a strong baseline response you can adapt with your own project examples.
Model courses as a directed graph and detect cycles. If a cycle exists, dependency order is impossible and answer is false.
Two standard approaches: DFS with recursion states (unvisited, visiting, visited) or Kahn algorithm using indegree queue. Kahn is iterative and easier to explain when interviewers ask for actual ordering too.
Complexity is O(V + E), where V is number of courses and E is prerequisites.
Discussion
Comments (0)
Share how this question came up in your loop, or add tips for others preparing.
Log in to comment on this question.