A fintech payments platform runs thousands of nightly jobs: fraud model refreshes, chargeback exports, ledger reconciliation, and regulatory reports. A single job running too early can invalidate downstream results and trigger compliance alerts. Your orchestration service receives a dependency graph of tasks and must produce a deterministic execution plan.
You are given n tasks labeled 0..n-1 and a list of dependencies deps, where each pair [a, b] means task a depends on task b (so b must execute before a).
Return a list representing a valid execution order that satisfies all dependencies. If multiple valid orders exist, return the one that is lexicographically smallest (i.e., at each choice point, pick the smallest task id available). If it is impossible to schedule all tasks due to a cycle, return an empty list.
n: int, deps: list[list[int]]list[int]Input: n = 6, deps = [[2,1],[3,1],[4,2],[4,3],[5,4]]
Output: [0, 1, 2, 3, 4, 5]
Explanation (step-by-step):
{0, 1} → pick 0, then 1 (lexicographically smallest).1, tasks 2 and 3 become available → pick 2, then 3.2 and 3, task 4 becomes available → then 5.Input: n = 3, deps = [[0,1],[1,2],[2,0]]
Output: []
Explanation: The dependencies form a cycle 0 → 1 → 2 → 0, so no valid execution order exists.
1 <= n <= 2 * 10^50 <= deps.length <= 3 * 10^50 <= a, b < na != bdeps may contain duplicate pairs; treat them as a single dependency.0..n-1 in the output if a schedule exists (even tasks that are isolated).