Binary search integer overflow
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) → intExamples
in
[[1,3,5,7],5]out2in
[[1,3,5,7],4]out2in
[[],9]out0What 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.
Run or narrate your approach, then ask the coach.