Code RoomConnection opened per request
MediumPrep Room Coding #4693

Connection opened per request

Vibe & agenticAlgorithms & data structuresMid–Senior~15 min

This Lambda (JavaScript) opens a MongoDB connection inside the handler on every request. Latency is high and Atlas shows connection churn. The AI says opening per-request is 'safer.' Correct it and explain the trade-off it missed.

Implement
simulate_connection_cost(is_cold_start: list[bool], handshake_ms: int, query_ms: int, reuse_client: bool) → list[int]
Examples
in[[true,false,false],120,10,false]out[390,3]
in[[true,false,false],120,10,true]out[150,1]
in[[],120,10,true]out[0,0]
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 15 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.