Question
You are given n tasks labeled 0..n-1 and a list of prerequisite pairs [a, b] meaning task b must be completed before task a. Return the lexicographically smallest valid ordering of all tasks (as a list). When multiple tasks are simultaneously available, always pick the one with the smallest label. If no valid ordering exists because of a cycle, return an empty list.
smallest_topo_order(n: int, prereqs: list[list[int]]) → list[int][4,[[1,0],[2,0],[3,1],[3,2]]]out[0,1,2,3]State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.