Practice heap medium level questions. It helps me to look at solutions when I’m stuck. You’re right, it’s hard to come up with this but it gets easier when you practice and study solutions. You’ll be stuck less and less with practice
What about the case when the max value that you pop from the heap is the value that you have just added, in that case would it still be valid to evaluate res using the current rate?
It's because since we know that the rates are increasing as we loop through, you can guarantee that total_quality * rate will be larger. I.e. the total quality was 10, we add a new guy with a higher rate, if we pop this guy because he has a higher quantity too, we'll basically be doing 10* higher rate which will be >= 10*prev rate
@@aadharjain313 it would be since you take the minimum. In the example I gave it would be min(10* prev rate, 10*higher rate) which is guaranteed to be 10*prev rate bc of what I mentioned
Please help me with this question. I'm going to use sliding window starting from 1 to len(quality) . From heap I'm going to pop when : while heap and len(heap) > k, heapq.heappop(heap). But I don't realize how to check when I am heappush to heap?
Hi navdeep, any good resource recommendations to learn how to determine space and time complexity for my own created solution? and also any website that can explains DSA terminology well?
while we are subtracting the maximum quality (since it's a maxheap) when the size of the heap becomes > k (k + 1), suppose our current quality is the maximum quality and we subtracted it from our total quality, but we are still using it's rate (which will be the maximum rate till now since rates are stored in ascending order) to get the minimum total wage by multiplying it with the total quality till now after the subtraction of the current maximum quality. basically we are multiplying the rate of that current quality with the total previous quality we already calculated an answer for. though this won't change our minimum answer till now since we are multiplying it with a greater rate, but still this is wrong. maybe we can also maintain a maximum quality and whenever we are popping the maximum quality, we won't use its rate to find the answer.
Yes, this bothers me as well. Maybe we should put to the heap not just quality - but pair we are processing. If if the pair we have to remove - is the same we just added - just skip it...
how is he using his pen(whatever) to write on browser bro can someone tell me? is there any software that is smooth as he is using right now? I am open for suggestion regarding software
There is a problem, we are calculating total_quality * rate, but one of the individual wage might hit the wage cap and must be discarded?Can you explain sir