Doubt in lecture

at 13:00 ,at line no 19. why are we taking prices[s.top()]<=currentprice and not prices[i]<=current price?

Hi Dipesh.
in question we have already assigned currentprice = price[i]. so prices[i]<=current which is equivalent to currentprice <=currentprice makes no sense. also we are looking for a day in past where price was greater than the current price.
Hope ur doubt is cleared.

so for any array lets say here it is prices[],we can directly write prices[s.top()] and it will give top element of the array?

yes u can do it directly. sir has used the extra variable just for explanation purpose.

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.

we can directly write s.top() also right?

no. logically think. in stack we are just storing the indices and not the prices. so to get to know about the price at that particular index u have to use price[s.top()]
Hope it clears all ur doubts.

okay thanks got it…

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.