Code RoomAnti-replay nonce window
MediumPrep Room Coding #286

Anti-replay nonce window

CodingSecurityMid–Senior~25 min

Implement anti-replay over a stream of signed requests. Each request is [nonce, timestamp]. Process them in order against a window of 'ttl' seconds and a tracking clock equal to the max timestamp seen so far. A request is ACCEPTED iff: its timestamp is within ttl of the current max (i.e. timestamp >= current_max - ttl) AND its nonce has not been accepted before within the live window. On accept, record the nonce and advance the max; also evict any remembered nonces whose timestamp is older than (new_max - ttl). Reject (do not record) otherwise. Return the list of booleans, one per request, indicating acceptance.

Implement
anti_replay(requests: list[list], ttl: int) → list[bool]
Examples
in[[["n1",100],["n2",101],["n1",102]],60]out[true,true,false]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[[["n1",100],["n2",101],["n1",102]],60][true,true,false]not run yetsample