Top kmost number

not getting approach I taught of using max heap of pair of freq and value using hashmap

First we store all the values in a hashmap.
We have to get k topmost elements, so frequency and value both are important.
We use max heap of type pair<int,int> because it will store both the frequency and value.
We can iterate the hashmap, and insert the pair {it->second,it->first} in our max heap.
Finally pop from the heap k times and display pq.top().second.

@S19APP-PP0108
not getting how to do

@S19APP-PP0108
this is my code not getting outout


Here is your corrected code. Please check it.

@S19APP-PP0108
now also not getting correct output

Please provide the input and required output here. I will check.

@S19APP-PP0108
input:
1
5 2
5 1 3 5 2
required output:
5 1 5 1 3 5 1 5 1

Top most frequency number is 5. And then you can display any number from 1, 2, 3.

@S19APP-PP0108
not getting correct output

I think you are talking about a different question. Please the hackerblock’s link of the question.

@S19APP-PP0108
its top kth number in running stream

Check this code and tell me if you are able to understand it.

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.