I don't understand why we are subtracting 1?

By default, lower_bound function returns the memory address of the element >= key value.
So, to avoid that we wrote the compare function so that we modify the comparison and return the memory address of the element less than equal to key.

But, still we have to subtract 1 at the end, Can you explain this?

hi @babayaga the compare function will return the address of the element that is STRICTLY greater than the key.

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.