1function binarySearch(arr, target) {
2 let left = 0;
3 let right = arr.length - 1;
4
5 while (left <= right) {
6 const mid = (left + right) / 2 | 0;
7 if (arr[mid] === target) return mid;
8 if (arr[mid] < target) left = mid + 1;
9 else right = mid - 1;
10 }
11 return -1;
12}
no lines flagged
#008PracticeMedium15 min · 120 XP
Binary Search Wrong Mid Calculation
This binary search overflows on large arrays due to an integer arithmetic fault. Find the problematic line.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.