BUY AND SELL- Doubt

Why my code is giving wrong answer??

hi, I have gone through your code here’s what you have missed

  1. in update function it should be while(val<max1) instead of while(val<=max1)
  2. also, you have to maintain count map which will maintain the frequency of each element present so that in case of freq=0 and you decrement the element so in that case you dont have to update
    I have fixed your code have a look:

In case of any doubt feel free to ask :slight_smile:
if you got the answer mark your doubt as resoved