Workspace/Coding labs
Loading progress

Measure overlap without double counting

Intermediate45 min

Implement span_coverage(root, children) where each interval is (start,end) in integer milliseconds. Return {"root_ms": duration, "covered_ms": union_length, "uncovered_ms": remainder}. Children may overlap or be empty, and zero-length intervals are allowed. Reject reversed intervals and children outside the root. Compute the union rather than adding durations. The child union is coverage of this local timeline, not a complete distributed critical-path algorithm.

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

Input(0,100), [(10,60),(40,80)]

Output{"root_ms":100,"covered_ms":70,"uncovered_ms":30}

Overlap from 40 to 60 counts once.
EXAMPLE 2

Input(5,5), []

Output{"root_ms":0,"covered_ms":0,"uncovered_ms":0}

A zero-duration root is valid.
solution.pyPython 3.12