Why are we subtracting 1 from the result?

Why are we using the statement : lower_bound(arr,arr+n,key,compare) -1 ? Why are we subtracting 1?

@HemantKumar hey normally lower bound hme finding key ke equal ya usse bda index deta hai but hme ek kam chyy use kyunki hme chota dhundna hai so -1 kia hai.

If u observe that
if u just write
lower_bound(arr,arr+n,key,compare)
without -1 then giving a money value which exists in the aray
would return a wrong value
it returns the next greater value in the array

hence the -1 is required so that even 120 and 100 would give us answer 100
in case -1 is not written then 100 would give answer 200 because of the comparator

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.