intmy_binary_search(intkey){intL=LOWER_BOUND,R=UPPER_BOUND;while(L<=R){intM=L+((R-L)>>1);if(arr[M]==key)returnM;if(arr[M]<key)L=M+1;elseR=M-1;}return-1;// key is not present}
boolis_valid(intval){/* return true if "val" is valid */}intmy_binary_search(){intL=LOWER_BOUND,R=UPPER_BOUND;while(L+1<R){intM=L+((R-L)>>1);if(is_valid(M))L=M;elseR=M;}returnL;}