Reduce interrupted audio playback events
Implement replay_audio(events), a teaching reducer returning active, queued, and heard state for start, chunk, play, and interrupt events.
Your task
- start sets a non-None response ID and clears unplayed queued chunks.
- chunk appends text only when its response matches the active non-None response.
- play moves up to count queued chunks to heard; reject negative count.
- interrupt clears queued chunks and active response but preserves heard chunks. Reject unknown event types.
Examples
EXAMPLE 1
Inputstart r1; chunk hello; play 1; interrupt; late chunk r1
Output{'active': None, 'queued': [], 'heard': ['hello']}
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor