FreeCareerPath
Build the PrimitiveEasy

Binary Search

Write `search(nums, target)` returning the index of `target` in the ascending list, or `-1`. search([-1, 0, 3, 5, 9, 12], 9) -> 4 search([-1, 0, 3, 5, 9, 12], 2) -> -1 Everyone knows this one and a surprising number of people write it wrong under pressure. Decide up front whether your range is inclusive on both ends, then keep every line consistent with that. Say the invariant out loud before you type — it is what the interviewer is listening for.

What to expect: A timer starts when you begin. Edit the starter code, run it against the test suite as many times as you like, then finish when you're done. The reference solution and interviewer follow-up questions unlock only after you finish.

Log in to start this session

Timed sessions and your results for "Binary Search" are saved to your account — logging in takes a few seconds.

Binary Search — FreeCareerPath