Collapse request status log
A mobile client retries flaky uploads, so the ingestion log can contain several lines for the same request id, each of the form "<request_id> <status>". Later lines for an id supersede earlier ones. Collapse the log so each request id appears exactly once, formatted as "<request_id> <status>" with its most recent status — but keep the ids in the order in which they FIRST appeared. Return the collapsed lines.
Implement
dedupe_retries(lines: list[str]) → list[str]Examples
in
[["r1 pending","r2 pending","r1 failed","r1 succeeded"]]out["r1 succeeded","r2 pending"]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 14 min
solution.py
InputExpectedGot
[["r1 pending","r2 pending","r1 failed","r1 succeeded"]]["r1 succeeded","r2 pending"]not run yetsample