Query state with two time cutoffs
Implement state_as_of(records, valid_at, known_at). Each record has integer valid, integer recorded, and string value. Include records with valid <= valid_at and recorded <= known_at. Return a copy of the eligible record with the greatest (valid, recorded) pair, or None. Exact duplicate records are harmless; conflicting values at the same pair are rejected across all input records. Reject noninteger time fields and nonstring values. Integer time is a synthetic teaching clock.
Your task
- Complete the starter function using the contract above.
- Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
- Run tests to record your result, then compare with the explained reference solution.
Examples
Inputrecords=[{"valid":8,"recorded":10,"value":"up"},{"valid":11,"recorded":14,"value":"down"}], valid_at=12, known_at=12
Output{"valid":8,"recorded":10,"value":"up"}
Inputsame records, valid_at=12, known_at=15
Output{"valid":11,"recorded":14,"value":"down"}
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor