PIXELBANKv9.1.0
Menu

Problem Statement

Given a CI pipeline's stage dependencies and the set of completed stages, list which stages are ready to run next.

Background

A stage is ready if it has not completed yet and all of its dependencies are in the completed set. Return the ready stages sorted alphabetically.

Your Task

def ready_stages(deps, completed):
  • deps: dict mapping stage name -> list of prerequisite stage names.
  • completed: list/set of completed stage names.
  • Return the sorted list of ready stage names.

Input Format

  • deps (dict), completed (list of str).

Output Format

  • A sorted list of strings.

Sample

print(ready_stages({"build": [], "test": ["build"], "deploy": ["test"]}, ["build"]))

Output:

['test']

Example:

Input:
print(ready_stages({"build": [], "test": ["build"], "deploy": ["test"]}, ["build"]))
Output:
['test']
Reasoning:
  • Convert the completed stages list ["build"] into a set {"build"}\{ \text{"build"} \} to allow for efficient membership checks during dependency validation.
  • Evaluate the "build" stage: it is already in the completed set, so it is excluded from the ready list.
  • Evaluate the "test" stage: it is not completed, and its only dependency "build" is present in the completed set, satisfying the condition that all prerequisites are met.
  • Evaluate the "deploy" stage: it is not completed, but its dependency "test" is not in the completed set, so it is not ready to run.
  • The final output is ['test']

Constraints:

  • Ready = not completed AND all deps completed.
  • Return names sorted ascending.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.