Top k most frequent number in a stream

unable to solve please help

hello @bhattanurag426

first try to solve this problem ->
u are given an array and u need to find top k frequent numbers of that array.

hint -> heap

yes in this we will maintain a heap of size k and store the elements according to the fre

and if the fre of next element is greater then the top we will pop out top element and push the new element

but i am unable to solve this one

then this one is just small extension of the problem that i suggest.

iterate from i=0 to n and prepare heap on [0…i] and print top k frequent .

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.