2 test cases are failing.
one i can guess with 1 input and the key is not that number.
Test cases failing
lower_bound doesn’t work in this way
if element not found then lower_bound and upper_bound doesn’t return last index
The lower_bound() method in C++ is used to return an iterator pointing to the first element in the range [first, last) which has a value not less than val. This means that the function returns the index of the next smallest number just greater than or equal to that number.
see these outputs
Correct condition will be
// correct one
if(arr[index]>m){
cout<<"-1"<<endl;
}else{
cout<<index<<endl;
}
i hope this helps
Thank you so much! You can close this thread.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.