Back to problems

Implement topological sort and tree boundary traversal

Algorithm · Snowflake · Medium

There are two independent tasks. Part 1: Course Ordering Suppose there are n courses numbered from 0 to n - 1. You are given a list prerequisites; each entry [a, b] means course b must be completed before course a can begin. Return an ordering of all courses that satisfies every prerequisite. If this is impossible because the prerequisite graph contains a cycle, return an empty list []. If multiple valid orderings exist, any valid ordering is accepted. Example 1:…

Checking your access…