Regarding the code

why we are doing -1 ???

as earlier lecture using upper bound we are getting exact index

There’s no need to do it as you have added your comp function to handle the case moreover if there is any doubt in this ? feel free to ask.

I can’t find any video in which money change problem is being explained using upper bound. Tell me the name of the video if there is any, so that i can help you.

but sir in the video of money change we are doing -1 though we have already use the comparator

See this


We are doing -1 because array index starts from zero
Moreover when you we will do this

lower_bound(arr,arr+5,8,compare)

Then if you don’t subtract -1 you will get 0, and arr[0] is 10. Which we don’t want. But when you do -1 then your result will be -1, as no coin for this result.

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.