fnplus / interview-techdev-guide

This repository contains curated technical interview questions by fn+geeks community
http://bit.ly/fnplusnow
MIT License
318 stars 325 forks source link

maxheap.py #597

Open hemishv111 opened 4 years ago

hemishv111 commented 4 years ago

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)

xlogix commented 4 years ago

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