Top K most frequent number in the stream

How can I approach this problem?

So I thought of unordered_map to store frequency of numbers and min Heap but it’s complicated. I need new approach! Any hint!

you can try this question using maps
it is not complicating

check this code

But I need to use priority queue in this problem because it’s in the heap section.

this is priority_queue based approach but not efficient

Can you kindly look into it? Given wrong answer.

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.

No, you’re not cleared my doubt.

this code is passing all the testcases

which input is giving wrong ans to you??

Bhaiya, after 10-11 days later if you’re trying to solve my doubt then it’s pretty sure that I have already solved it. Because, this is my code and my responsibility to solve this bug. Your work to help me on that thing when I raised my doubt which you haven’t done. So, I took others help. So why I even raise my doubt if you’re not taking my doubt seriously.