binary search easiest way
int binsearch(int lo, int hi)
{
	while(lo < hi)
	{
		int mid = lo + (hi-lo)/2;
		if(check(mid))
			hi = mid;
		else
			lo = mid + 1;
	}
	return lo;
}binary search easiest way
int binsearch(int lo, int hi)
{
	while(lo < hi)
	{
		int mid = lo + (hi-lo)/2;
		if(check(mid))
			hi = mid;
		else
			lo = mid + 1;
	}
	return lo;
}Binary Search
const numbers = [1, 2, 3,4,5,6,7,8,9,10];
function binarySearch(sortedArray, key){
    let start = 0;
    let end = sortedArray.length - 1;
    while (start <= end) {
        let middle = Math.floor((start + end) / 2);
        console.log(middle)
        if (sortedArray[middle] === key) {
            // found the key
            return middle;
        } else if (sortedArray[middle] < key) {
            // continue searching to the right
            start = middle + 1;
        } else {
            // search searching to the left
            
            end = middle - 1;
        }
    }
	// key wasn't found
    return -1;
}
console.log(binarySearch(numbers,4))Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us
