Code RoomBinary search integer overflow
HardPrep Room Coding #4005

Binary search integer overflow

Vibe & agenticAlgorithms & data structuresSenior–Staff~20 min

An AI assistant produced this C++ to find the index of a target in a sorted vector, returning a default when absent, for a hot lookup path:

It returns correct indices in unit tests on a 10-element vector. What latent bugs would a staff engineer flag?

Implement
search_sorted_index(sorted_values: list[int], target: int) → int
Examples
in[[1,3,5,7],5]out2
in[[1,3,5,7],4]out2
in[[],9]out0
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 20 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.