not getting approach I taught of using max heap of pair of freq and value using hashmap
Top kmost number
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.
Here is your corrected code. Please check it.
Please provide the input and required output here. I will check.
Top most frequency number is 5. And then you can display any number from 1, 2, 3.
I think you are talking about a different question. Please the hackerblock’s link of the question.
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.