Skip to content

Bug Report for binary-search #5682

@neel2911

Description

@neel2911

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions