Yelp Interview Question

find the smallest K elements of a given list

Interview Answer

Anonymous

Jun 22, 2017

keep a max heap with k elements and iterate over the array add an element and then remove the max element in the heap repeat until the array has ended then the max heap represents the smallest K elements