How to find the top n products based on number items sold. We can use max heap to keep track of number of times product was sold and find the top n from the heap. But the problem is let's say we have to find in real time when a product is brought we have to update the count and then heapify. Finding the product in heap is again O(N), deleting the product and adding back the product with updated count is O(LogN) Is there any better solution?