Workspace/Coding labs
Loading progress

Find a temporally coherent evidence path

Advanced75 min

Implement find_evidence_path(edges, start, goal, at, known_by, max_hops=3). Filter a directed graph by valid and recording times, then return evidence IDs for a deterministic shortest path.

Your task

  1. Each edge has source, target, valid_from, valid_to (integer or None), recorded_at, and evidence_id. Fixtures use string node/evidence IDs and integer times.
  2. Require max_hops to be an exact nonnegative integer; raise ValueError otherwise. Reject any edge whose non-null valid_to <= valid_from.
  3. An edge is eligible when valid_from <= at, valid_to is None or at < valid_to, and recorded_at <= known_by.
  4. Traverse eligible directed edges breadth first, ordering outgoing edges by (target, evidence_id). Use visited nodes to prevent cycles. Return the first shortest path as a list of evidence IDs.
  5. Return [] when start equals goal and None when no path exists within max_hops. Validate intervals before the start-equals-goal shortcut. The function assumes evidence claims are already authorized and structurally validated; it does not infer relation semantics.

Examples

EXAMPLE 1

InputA->B supported by E1 and B->C by E2, both valid and known at time 3

Output['E1','E2']

If E2 starts at time 4, no such path exists at time 3.
solution.pyPython 3.12