Skip to content

Instantly share code, notes, and snippets.

@nerohoop
Created January 11, 2018 01:26
Show Gist options
  • Save nerohoop/65a8b26d0f5e7715e0b785e13c5d59d2 to your computer and use it in GitHub Desktop.
Save nerohoop/65a8b26d0f5e7715e0b785e13c5d59d2 to your computer and use it in GitHub Desktop.
1. Create a Min Heap of size k+1 with first k+1 elements. This will take O(k) time
2. One by one remove min element from heap, put it in result array, and add a new element to heap from remaining elements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment