← Questions

Smallest valid task order from dependencies

0
AppleCodingLast asked Aug 2026

There are n tasks numbered 0 to n - 1, done one at a time, and a list of pairs [a, b] meaning a must finish before b starts. Return an order that respects every dependency; among all valid orders, return the smallest one when compared position by position. If the dependencies contain a cycle, report that no order exists. (Kahn's algorithm with a min-heap instead of a plain queue.)

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding