← All problems
Binary Search (classic)
Given a sorted integer array and a target value, return the target's index, or -1 if it is absent. Implement binary search iteratively and handle the midpoint computation safely.
Complexity
Time O(log n), Space O(1)
Common pitfalls
- (lo+hi)//2 overflow in fixed-width languages
- Infinite loop from wrong bound updates
Your solution
Log in to save your code and track progress.