Adobe Interview Question
Developer Program EngineersCountry: India
Interview Type: In-Person
should use min heap, which will tell you the smallest number in the heap (which is the kth largest in the stream). max heap does not tell you that.
yes, we should use minimum heap in this case, insert first k numbers to minimum heap. Now for every other number just check with the root of heap, if its less than the root of the min heap( that is smallest element) do nothing but if its greater than the root of the min heap, remove the root and in its place insert the new element ,apply min heap on root.This way every time heap will represent first k maximum number)
when u put the question please put with some input and expected output. The Question is sometimes not understandable.
Use max heap of k size, update(Heapify) it whenever new number comes
- shani July 03, 2012