Adobe Interview Question
Software Engineer / DevelopersCountry: India
Interview Type: In-Person
I think heap is the best solution. We have to maintain a 10 element maxheap (maximum element at top) - elements will be kept in the heap along with their frequency. Before inserting into the heap we have to check if the word exists in the heap; if so increase the frequency of the heap and rearrange the heap on the basis of frequency.
Can you please explain your approach. I don't think just max heap of size 10 can work.
for example if you have 30 elements and 10 elements of count 2 and 1 of count 3. lets say this 1 element came as 1st spot and rest 2 are last two. As per your approach, you will get this element removed since after 21st element, this will be of least count.
Hashing with min-heap.
- Psycho September 24, 2012If the count of word is greater than the top of the min heap then replace this with the top of the min-heap. So by doing this min-heap size will not be greater than 10.