I did not understand how we are using the comparator and why are we doing -1 after using the comparator.
the comparator was a<=b then we should enter 160 and get 100 but we get 200 ,why?
Money change problem
@Gautampriyadarshi hey,if you use your own comaparator in lower bound function then you dont have to subtract 1 from ans as comparator will use <= so give index smaller than or equal to finding element,but if you use normal lower bound function without comparator so then subtract 1 as normal lb function gve index of larger element or equal to finding key index if element found so subtract 1 to get the required ans.Hope youget it 
yes but it is not giving I tried
@Gautampriyadarshi hey please send your code,it will work fine without comparator if you subtract 1 from it.
https://ide.codingblocks.com/s/230336 this is the code ,at 168 it should give 100 but gives 200 but only after subtracting 1 get 100 and also at amt =100 I get 100
in the video to 1 is being subtracted
@Gautampriyadarshi hey there is misunderstanding,if we dont use comparator, then the lower bound function gives the first value in the sorted array that is greater than or equal to the value to be found i.e it will ignore all values smaller than the value to be found. But, when we define a comparator same as defined in the lecture, the lower bound function ignores all the value smaller than or equal to the value to be found and hence will always return the index of key which has value greater than the value to be found. Hence we will have to subtract 1 from index in order to get the index of key which has value smaller than or equal to the required value.
For eg. arr=[1,2,3,5,7,9,13]
and we need to find lower bound of 5 and 6.
so if we use lower_bound without comparator, we will get ans as value=5 -> index=3 and value=6 -> index=4.
but if we use the comparator as discussed in lecture, we will get ans as value=5 -> index=4 and value=6 -> index=4.
So we will have to subtract 1 in latter case to get index of value smaller than or equal to the value to be found
using a<=b, comparator function returns true for all elements <= value to be found. When the comparator function returns false at that time we see that the current index might be the answer. If we dont use comparator function, it returns true only for elements < value to be found.
Since lower bound uses binary search approach internally, it use comparator <= condition in order to search for element greater than value to be found. In the later case lower bound use < condition to find the required index.
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.
Hey I don’t understand this. In the sorting function
we return, a<b, which means if the current number a is smaller then choose this number over b. Not the opposite. Comparators work on positive logic and not negative.
@rachitbansal2500 hey dont think in that way < sign doesnot indicate ki woh smaller wali condition hi hogi ,jo conditions hai unke hisaab se conparison hota hai ,ap ek bar dono condition lgakr output check kro ,you will get it.
Can you please explain in detail? I am confused about the outputs. When I am using a<b then it is considering the answer as 200 even after -1.
@rachitbansal2500 hey please make your own comparator one with condition ab and now apply lower bound function ,you will get what I am trying to say ,also you have to do -1 as mentioned by me in explanation above.