Why are we subtracting 1 from lb after we have passed the comparator function as an argument to the lower bound function??
Initially we were subtracting 1 because lower bound function returned the address of an element which was greater than or equal to key(here, money), but now that we have used a comparator, why do we need to subtract 1?
Doubt in the lesson money change problem
hello @aayushitalwar02
intially with lower we had one issue that sometimes if key is already present in the array then it return that index .
so for this we are not suppose to decrement index by one becuase value we got at that index is already less than equal to key. but we were decrementing .
so to avoid this we have defined comparator to change lower bound functionality and make it work as upper bound.
so now with comparator we will always get value which will be greater than key hence we need to subtrct -1 always
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.