Implement prototype(n: int, edges: list[tuple[int, int]]) -> list[int] | None and solve with the same signature. Vertices are 0..n-1; (u,v) requires u before v. Return the lexicographically smallest valid full ordering, or None when any directed cycle prevents one. Duplicate edges count once. n=0 returns [].
Example: (3, [(0,2), (1,2)]) returns [0,1,2].
Raise ValueError for negative n or invalid endpoints. Prototype: test permutations in lexicographic order. Final: maintain indegrees and a smallest-first legal frontier. Preserve inputs, including on failure.
Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
Loading editor…
No results yet.
Complete the starter code, then run the checks.
Results and errors will appear here.