Workspace/Coding labs
Loading progress

Join speech intervals to screen frames

Intermediate45 min

Implement align_segments(frames, segments, max_gap), returning a list of frame IDs or None in segment order using an offline nearest-midpoint rule.

Your task

  1. Frames are dictionaries with time and id; segments have start and end. Timestamp units are shared.
  2. Choose nearest frame to each midpoint, breaking ties by earlier frame time then lexicographic ID.
  3. Return None when no frame exists or the nearest gap exceeds max_gap.
  4. Reject negative max_gap and any segment whose end precedes start; do not modify inputs.

Examples

EXAMPLE 1

InputFrames a@100, b@300; segment [180,220]; max_gap=100

Output['a']

The midpoint ties, so the earlier frame wins.
solution.pyPython 3.12