Algorithm · ByteDance · Medium
Problem You are given n tasks numbered 0 through n - 1 and m dependency rules. Each rule is a directed edge u v, telling you that task u must execute before task v. Find any ordering of all n tasks that obeys every dependency: for every edge u -> v, u must appear earlier than v. If the dependency graph contains a cycle, no such ordering exists; output IMPOSSIBLE. Function Signature The judge expects the following function: Return a list of task labels in a valid execution…
Checking your access…