Top K most frequent numbers

whats wrong in this code : https://ide.codingblocks.com/s/229002

@YashJ,

Sample test case:
8 4
5 1 3 5 2 1 1 3
Correct answer:
5 1 5 1 3 5 5 1 3 5 1 2 3 1 5 2 3 1 5 2 3 1 3 5 2
Your answer:
5 1 5 1 3 5 5 1 3 5 1 2 3 5 1 2 3 1 5 2 3 1 5 3 2

thank you I solved it but can this question be solved using heap?

@YashJ,

you can try it by putting the less frequent element first.

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.