interview-techdev-guide
interview-techdev-guide copied to clipboard
maxheap.py
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)
Please raise a new issue or link an existing issue to this PR. Read our contribution guidelines!