Top k frequent in stream of element

can u explain how to do this question, any hint?

Hello @sheikhhaji18 have you thought of any approach so that we can discuss this question
.

Since it is a type of question where we have to find maximum element, so we can make heap , and put elements upto k size at each point according frequency

but how print elements from heap each time? it becomes empty right

yes right, you are going right.
i am sharing this code tell me if you dont understand anything.


in this code the unique concept is of functor only and i hope you know functor.
Happy Learning!!


i have doubt , i have asked my doubt in this link,
bro what is the time complexity of this code?
O(N^2)+O(LOGN)+O(LOG K) RIGHT?

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.