Course Schedule (Ordering)
Medium · Graphs · about 25 minutes
Asked at Airbnb, Amazon, Atlassian, Databricks, Meta, Palantir, Twilio, ServiceNow, Asana, Notion, Datadog, Confluent, GitLab, HubSpot, Canva, Cohere, Hugging Face, Airtable, Akamai.
There are n courses labeled 0..n-1 and a list of prerequisite pairs [a, b] meaning you must take b before a. Return a valid order to take all courses, or an empty list if impossible.