here you have mentioned
lb=lower_bound(coins,coins+1,compare)-coins-1;
i want to ask that if u are using compare class here then whats the need of -1 here .and if u have used -1 then the output should be 50 not 100 then how its still giving the ouput 100
Use of -1 in the statement
hey @ankit2705ojha
If u observe that
if u just write
lower_bound(arr,arr+n,key,compare)
without -1 then giving a money value which exists in the aray
would return a wrong value
it returns the next greater value in the array
hence the -1 is required so that even 120 and 100 would give us answer 100
in case -1 is not written then 100 would give answer 200 because of the comparator
@ankit2705ojha hey,when you use comparator then you don’t have to do -1 as comparator will give you one less index itself,but when you dont use comparator then you have to do -1 hope you get it.
but here in the vedio although he have used comparator then also he used that -1 here…that was actually what i was bothered about
but why it is giving 200 even when a comparator was used and in comparator he has even used return a<=b .so it should return 100 without that -1
@ankit2705ojha bro code check kro agar ap comparator use kroge to woh apko ek less lakr dega already dont use -1 and check again.