Skip to content

Conversation

hemishv111
Copy link

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 xlogix self-assigned this Oct 24, 2019
@xlogix xlogix added Hacktoberfest Not assigned to an issue PR has to be assigned to an issue. labels Oct 24, 2019
@xlogix xlogix added this to the Hacktoberfest milestone Oct 24, 2019
@xlogix
Copy link
Member

xlogix commented Oct 24, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest Not assigned to an issue PR has to be assigned to an issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants