Money Change Problem

I’m confusing about the compare function in lower_bound().

  1. Why we have to overwrite it to return a <= b? What actually compare() does when we pass it as a parameter in lower_bound() function?
  2. Why we have to subtract 1 from the lb?

Thank you so much for your help

@halihoof there is no need to use compare in lowerbound coz if you try it on your compiler at overwrite a<=b it just converts into upperbound. like first it gives greater than eq value but writing compare gives > value so upperbound. we are subtracting 1 just because of indexing.
best way to clear this is doing on your own . write the code and keep giving ip op for diff conditions (best way to learn)
i hope your doubt is clear dont forget to mark the doubt as resolved :smiley:

@vatsal38
It’s like we’re trying to convert lower_bound() to upper_bound(), right?
I think it’s more clearer if we use upper_bound() because after find the value, just subtract 1 and it’ll give me the correct index.
I’ll be better understand if it’s upper_bound() :grin:

yes @halihoof just use lower and upper

1 Like