Binary Search
easypy_basicsImplement find_value(nums, value).
nums is a list (or range) of integers sorted in non-decreasing order; it may
be empty. Return True if value is present, otherwise False. Use binary
search — O(log n) time, O(1) extra space.
The in operator, the bisect module, and .index() are not allowed: write
the search yourself. (One test runs on a huge range where a linear scan would
time out.)
Constraints
- no bisect
- no index
Your solution
Edit find_value and run the real pytest suite in your browser — no install required. Your code is saved locally.
Loading the Python runtime (first run only)…
Hints
Hint 1
Keep a [lo, hi] window of indices; compare nums[mid] to value and halve the window each step.
Hint 2
Two returns: True inside the loop on a hit, False after the loop ends.