Workspace/Coding labs
Loading progress

Resolve unique provenance sources

Intermediate45 min

Implement source_leaves(graph, claim). The graph maps every artifact ID to a list of input artifact IDs; a leaf has an empty list. Return a sorted list of unique leaf IDs reachable from the claim. Reject a missing claim, unknown referenced artifacts in the reachable subgraph, and reachable cycles. Unrelated components are not traversed. Repeated paths to one observation do not create independent evidence.

Your task

  1. Complete the starter function using the contract above.
  2. Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
  3. Run tests to record your result, then compare with the explained reference solution.

Examples

EXAMPLE 1

Inputgraph={"report":["forecast","obs"],"forecast":["obs","schedule"],"obs":[],"schedule":[]}; claim="report"

Output["obs","schedule"]

Shared obs is counted once.
EXAMPLE 2

Inputgraph={"a":["b"],"b":["a"]}; claim="a"

OutputValueError

Circular references provide no source leaf.
solution.pyPython 3.12