Code RoomRejected photo uploads
EasyPrep Room Coding #4713

Rejected photo uploads

CodingConcurrencyEntry–Mid~14 min

A phone backup service uploads photos in the background and never lets more than limit uploads run at the same time. Its log is a list of events, each a string "id|action" such as "p14|start" or "p14|done". Walk the events in order. A "start" is admitted when fewer than limit uploads are running, and that upload joins the running set. A "start" that arrives while limit uploads are already running is rejected: the photo never uploads, and a later "done" carrying its id changes nothing. A "done" for a running upload removes it and frees its slot. Every id starts at most once. Return the ids of the rejected uploads in the order they were rejected, or an empty list when every upload was admitted.

Implement
rejected_uploads(limit: int, events: list[str]) → list[str]
Examples
in[2,["p1|start","p2|start","p3|start","p1|done","p4|start"]]out["p3"]
in[1,["a|start","b|start","b|done","c|start","a|done","d|start"]]out["b","c"]
in[2,["x|start","x|done","y|start","y|done"]]out[]
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
InputExpectedGot
[2,["p1|start","p2|start","p3|start","p1|done","p4|start"]]["p3"]not run yetsample
[1,["a|start","b|start","b|done","c|start","a|done","d|start"]]["b","c"]not run yetsample
[2,["x|start","x|done","y|start","y|done"]][]not run yetsample