hard20 pts · first answer countsarraysbinary-searchdebugging
Binary search that never ends
This search for the last index with a[i] <= target loops forever on some inputs. Why?
while (lo < hi) {
const mid = Math.floor((lo + hi) / 2)
if (a[mid] <= target) lo = mid
else hi = mid - 1
}Discussion 0
Join free to post in the discussion.
Related questions
- What a 504 from Nginx meansBackend Developer
- Python default list surpriseBackend Developer
- Cost of reading arr[i]Backend Developer
- Inserting at the front of an arrayBackend Developer
- Why push is amortized O(1)Backend Developer
- Changing one character of a stringBackend Developer
- Reversing a simple stringBackend Developer
- slice vs spliceBackend Developer