Skip to interview prep
Apexed
Problem list118 / 143

118. Plan Parallel Deployment Waves

MediumDependency graphs

Jobs are numbered from 0 to count - 1. Each dependency [before, after] means that before must finish in an earlier wave than after.

Start every currently unblocked job in each wave. Return the waves in execution order, with ascending job IDs within each wave. Return an empty list if any cycle makes a complete schedule impossible.

Example 1

Input: count = 6, dependencies = [[0,2],[1,2],[0,3],[3,4],[2,4]]
Output: [[0,1,5],[2,3],[4]]

Example 2

Input: count = 3, dependencies = [[2,1],[0,1]]
Output: [[0,2],[1]]

Constraints

  • 0 ≤ count ≤ 10,000 and at most 50,000 dependency pairs.
  • Pairs are unique and reference existing jobs. A job can depend on itself.

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 6 hidden and sample tests.

Code runs in an isolated browser sandbox. Progress and submissions are saved on this device.

Plan Parallel Deployment Waves — coding interview practice — Apexed