interview-techdev-guide icon indicating copy to clipboard operation
interview-techdev-guide copied to clipboard

maxheap.py

Open hemishv111 opened this issue 4 years ago • 1 comments

Since Python's heapq implementation does not have built in support for max heap, we can just invert the values stored into the heap so it functions as a max heap. Max heap is better than min heap because we don't actually have to store all N points into the heap, we just need to keep K min points.

Time Complexity: O(N Log(K)) Space Complexity: O(K)

hemishv111 avatar Oct 24 '19 04:10 hemishv111

Please raise a new issue or link an existing issue to this PR. Read our contribution guidelines!

xlogix avatar Oct 24 '19 05:10 xlogix