← Problems26. Pipeline task execution orderHardPython
00:00 / 20:00

Pipeline task execution order

Hard·Acceptance ·Asked at Amazon, Google

Given tasks and their upstream dependencies, return the order a scheduler should run them in. Detect cycles rather than looping forever.

Input schema

solve(tasks: list[str], deps: list[tuple[str, str]]) -> list[str] each dep is (upstream, downstream)

Example

tasks = ["load", "clean", "report"] deps = [("load", "clean"), ("clean", "report")] Output = ["load", "clean", "report"]

Constraints

  • Ties break on task name ascending, so the output is deterministic
  • A cycle raises ValueError naming one task in the cycle
  • A dependency on an unknown task raises KeyError
  • Up to 200,000 tasks and 1,000,000 edges

Topics

data modeling

Similar problems

Community-reported interview topic. Not an official company question and no affiliation is implied.

solution.py
Loading editor…
Draft not saved yet · Spaces 4 · UTF-8 · ⌘↵ run, ⌘⇧↵ submit
Nothing run yet

Run against the public tests, or submit to score against all of them.