Above is the Link to my code.
Identify problem in my code
You shall maintain quantity of each kind of items rather than total items,
update particular items’ quantity for each call.
Well I am maintaining quantity of each item in the fenwick tree and total Quantity in a variable so as to give answer to the items greater than a particular item.
Can you please explain whats wrong with my logic?
Why Fenwick?
Simply map use kro na…
Beacuse it is solvable using fenwick tree and is in fenwick tree section of your own course xD
Using maps we will have overall complexity as O(NQ)
@vivek_oberoi
In case of - operation , you are only supposed to decrement in case that item exists. Consider the case when the the frequency of that item is 0 i.e. the item does not exist in our stock and we get a negative query to decrement its count. In such a case , we should do nothing. But your code goes on to decrement the value in BIT and hence that gives the wrong answer.
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.