We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Dear Friends, I have seen that for this problem, many people are focusing on 'moving window'. But as you know it can be worst if there is a new max element in each window and if there are lot of queries to process like Q > 1000,
In this situation, the best choice would be 'Priority Queue using heap', O(log n) insertion and O(log n) poping out will make the things faster and easier.
for this I have used two priority queues(max heap) to manage the flow and the worst case complexity in any situation falls down to O(nlogn)
Queries with Fixed Length
You are viewing a single comment's thread. Return to all comments →
Dear Friends, I have seen that for this problem, many people are focusing on 'moving window'. But as you know it can be worst if there is a new max element in each window and if there are lot of queries to process like Q > 1000,
In this situation, the best choice would be 'Priority Queue using heap', O(log n) insertion and O(log n) poping out will make the things faster and easier. for this I have used two priority queues(max heap) to manage the flow and the worst case complexity in any situation falls down to O(nlogn)