
Implement a function that locates key in an increasing sequence you can only read one element at a time through the callback at, spending at most 24 reads.
binary_search(7, 8, at) over {2, 4, 6, 8, 10, 12, 14}Expected result
idx=3 probes<=24For your own tracking. Tests grade your code.
binary_search(5, 3, at) over {1, 3, 3, 3, 5}Expected result
idx=1 probes<=24binary_search(7, 9, at) over {2, 4, 6, 8, 10, 12, 14}Expected result
idx=-1 probes<=24binary_search(1000000, 1999998, at) with at(i) = i * 2Expected result
idx=999999 probes<=24the same call, answered by reading index 0, then 1, then 2, and so onExpected result
idx=999999 probes=1000000Expected files
binary_search.cAllowed functions
None. Write every helper yourself.
Allowed headers

v0.40: Create exercises. Challenge the community.
Meet Studio →Implement a function that locates key in an increasing sequence you can only read one element at a time through the callback at, spending at most 24 reads.
binary_search(7, 8, at) over {2, 4, 6, 8, 10, 12, 14}Expected result
idx=3 probes<=24For your own tracking. Tests grade your code.
binary_search(5, 3, at) over {1, 3, 3, 3, 5}Expected result
idx=1 probes<=24binary_search(7, 9, at) over {2, 4, 6, 8, 10, 12, 14}Expected result
idx=-1 probes<=24binary_search(1000000, 1999998, at) with at(i) = i * 2Expected result
idx=999999 probes<=24the same call, answered by reading index 0, then 1, then 2, and so onExpected result
idx=999999 probes=1000000Expected files
binary_search.cAllowed functions
None. Write every helper yourself.
Allowed headers

Run the tests to grade your code
Build your code, then check each test here. Open a result to inspect its output.