Doubt in line 17 of code

Compare function is giving us no. less than equal to money . Right? then in int lb = lower_bound (coins, coins+n, money, compare)-coins why did we subtract 1 from it . Why can’t we get the index of coin which is less than equal to the money without subtracting 1 .

@apoorvagupta1 lowerbound returns iterator to greater than equal to and upperbound strictly greater . when we use comparator in lowerbound it also returns strictly greater so -1

Then why are we returning true if a<=b in compare function if you’re saying it is strictly greater ? Doesn’t that mean we are using comparator in lowerbound so as to return coins which are greater than or equal to money because if we take money=200 this code will fail? I think Instead of a<=b it should be a<b , then only it is passing all the testcases.

@apoorvagupta1 best way is too run your code for diff cases it will come clear but here let me right
lowerbound without comp gives greater than equals
loweround with comp a<=b gives greater than
upperbound gives greater than
so no need to use comparator just use upper and lower and acc do -1
now try some cases on your compiler