Bug Report for https://neetcode.io/problems/binary-search
I don't know why but this code passed
search(nums, target) {
let l = 0;
let r = nums.length - 1;
while(l <= r) {
const m = Math.floor(l + r);
if(target < nums[m]) {
r = m - 1;
} else if(target > nums[m]) {
l = m + 1;
} else {
return m
}
}
return -1;
}
Please check this line const m = Math.floor(l + r); even if I did not divide it by 2.
Expectation:- one of the test cases should fail.
Actual:- all the test cases are passed.
Bug Report for https://neetcode.io/problems/binary-search
I don't know why but this code passed
Please check this line
const m = Math.floor(l + r);even if I did not divide it by 2.Expectation:- one of the test cases should fail.
Actual:- all the test cases are passed.