Regarding the lecture

Why sir is still using lb = lower_bound(coins,conis+n,key)-coin - 1 why still we need to subtract -1 when we are using our own comparator

Hello @talhashamim001 if you want to do this without STL then you can see this;


if you have any doubt you can ask here:
Happy Learning!!

sir Im new to programming Im not able to understand your code but seeing dp[] I guess u have used dynamic programing which I don’t know

I wanted to ask if after modifying the comparator in the video if we will write lb = lower_bound(coins,conis+n,key)-coin - 1 then we will get the index of the element before that element na?

Like if we want to find 100 and we have a[] = { 1,2,3,4,100,200}

Hello @talhashamim001 this is the question of dynamic programming only.
you have reached or covered the topic of dynamic programming till now?
if you have not covered then you can leave this question nod andi suggest you to try afterwards so that you can get the concept and can solve yourself as well.
if you want i can try to exlain you as well,
Happy learning!!

Hello @talhashamim001 to your query above yes right .
While using lower bound function you have subtract the index of first element as well.

please check the video at 4:11 sir has not used, I’m confused now

@talhashamim001 please wait i have to confirm then because there is possibility that he is using some other technique as well.

@talhashamim001 if you have watched the video carefully then you must have noticed that in the video sir have done like this;
int lb=lower_bound(coins,coins+n,money)-coins;
when he is subtracting the coins then he is doing nothing but subtracting the first index so that index can be known of that element.
if you stilll have any doubt you can ask here;
Happy Learning!!

i wanna know why he is subtracting 1

with the new comparator function we will be getting ingex of 100 after subtracting coins why -1

@talhashamim001 no you will not get if you will not do -1 then you will get element present at +1 index because lower bound gives you the index of the element to which this element is present 1 next.
as in the case of 168 it was giving for 200 you can check this by not writing -1.
Happy Learning!!

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.