Workspace/Coding labs
Loading progress

Compute deterministic ready batches

Intermediate45 min

Implement ready_batches(graph), returning lexicographically sorted dependency layers for a closed DAG. All nodes, including roots, must be dictionary keys.

Your task

  1. Return an empty list for an empty graph.
  2. Each batch contains every remaining node whose predecessors are complete, sorted by node name.
  3. Reject an unknown predecessor or a cycle with ValueError.
  4. Repeated predecessor entries are equivalent to one edge; do not mutate the input.

Examples

EXAMPLE 1

Input{'a': [], 'b': ['a'], 'c': []}

Output[['a', 'c'], ['b']]

The first batch exposes two independent tasks.
solution.pyPython 3.12