Infinite polling drains battery
An AI wrote this Swift method to keep a delivery map fresh by polling the server for the courier's position. It works, but users report the app drains the battery and runs hot, and your backend sees a constant request flood even when the app is idle in the background. What's wrong and how would you fix it?
Implement
plan_poll_times(state_changes: list[str], foreground_interval_ms: int, background_interval_ms: int, horizon_ms: int) → list[int]Examples
in
[["0:foreground"],200,200,1000]out[0,200,400,600,800,1000]in
[["0:foreground","5000:background","12000:foreground"],2000,0,15000]out[0,2000,4000,12000,14000]in
[["0:foreground","3000:stopped"],1000,0,10000]out[0,1000,2000]What a strong answer looks like
Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it (tests, edge cases, reading critically), and how you’d re-prompt or decompose to get it right.
0:00 of about 18 min
Vibe & agentic: describe the solution in plain language (or narrate it) and the coach grades your approach.
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.