Consfusion in comparators

As u have said that
int lb=lower_bound(coins,coins+n,money,compare)-coins-1
in this we will not subtract -1 every time it will fail in case of 100 so to avoid this we have compartors then why u have use -1 in code,

@n.nishchaya2000 hey agr hm apna comparator bna rhe hai to hme woh already 1 minus krke return krega hi hme -1 krne ki jaroorat nhi hai ,code me galti se krdia hoga aur normally lower bound function use krne pr hme krna pdega -1.

that’s what i am saying if it was done by mistake, but still it is giving me wrong output when i am going to remove -1

@n.nishchaya2000 please send me code I will submit,Actually question me requirement uski hogi ya sir ne comparator us hisaab se bnaya hoga pls check that

using namespace std; #include #include bool compare(int a,int b) { return a<=b; } int main() { int coins[]={1,2,5,10,20,50,100,200,500,2000}; int n=sizeof(coins)/sizeof(int); int money=168; while(money>0) { int lb=lower_bound(coins,coins+n,money,compare)-coins; cout<<coins[lb]<<","; money-=coins[lb]; //give us the left amount } }

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.