Simple doubt

Suppose we are given an array “a”, of size ,let’s suppose “n”. Suppose we have a value “x”.
what does the statement cout<<lower_bound(a,a+n,x)-a; print??

I know about lower_bound for arrays/vectors, but I have never encountered the expression above.

1 Like

It will find the index of the lower bound of x.

1 Like

It finds the first index in the range [0,n) whose value is not less than x.

E.g. arr={10,20,30,40,50}

lower_bound(arr,arr+5,30) will return index 2 since its value,30, is not less than x(=30)

1 Like

Thanks!!

Thank you!