Top k most frequent no in a stream

how to solve this problem using comparators that compaers first on the basis of frequency and then on the base of value…
plz provide the code for this kind of solution as well…

hi @S19LPPP0202, if you want solution based on priority_queue and comparators ,
refer to the link below :-

this is little inefficient because you have to empty your priority_queue and again refill it making your time complexity as O(n*klog(k))

but there is a way to solve this question without using priority_queue and comparators and that even in O(n*k) , refer the below post , you will learn a new way to do this question :-

In case of any doubt feel free to ask :slight_smile:

1 Like

didnt understand the geeks for geeks solution …plz explain it especially the for loop of the code given …in the solution

come to personal chat i will give you my number , its difficult for me to explain whole idea here

how to come to personal chat??

check your inbox … …

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.