Showing posts with label Get K Max. Show all posts
Showing posts with label Get K Max. Show all posts

Get K Max and Delete K Max in stream of incoming integers

Get K Max and Delete K Max in stream of Incoming Integers 

Solution 1 : Using Min Heap

Algorithm :
1) Keep a Min & Max Heap of K size
2) Store first K elements in them.
3) If a new element comes with smaller or larger than root then reorder   heap.