Return a valid course completion order
OracleSoftware Engineer · OnsiteLast updated
This question evaluates understanding of graph algorithms and dependency resolution, specifically skills in cycle detection and producing valid orderings of tasks.
You are given an integer n representing n courses labeled 0..n-1 and a list of prerequisite pairs prerequisites, where each pair [a, b] means you must complete course b before course a.
Return any valid ordering of courses you can take to finish all courses. If it is impossible due to cyclic prerequisites, return an empty list.
Requirements:
- The solution should run efficiently for large
nand prerequisite lists.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.