@elmirap Thanks for the sharing those. I'm still trying to fully understand this.

Assuming we a stream of key val pairs: thinking about using a heap.

Are you removing the elements from the heap? I thought its just returning values of the top K stocks. Is even returning top K from heap is O(klogn)?

Secondly I thought "heapify" is O(n) --- you wrote O(log n) <-- I think O(log n) is for inserting into a existing heap. And heapify is building a heap from scratch.

Inserting into a heap is O(log n). What is the final datastructure being used here? Sorry python user here..

Please correct me if I am wrong.

Bloomberg