RUN ERROR : Top K most frequent number

I am getting the correct answer for a number of test cases.
But while I submit I am facing run error in my code.
Please have a glance at my code.
I have provided the comments for each step I implemented.

check ur code for the i/p

8 4
5 1 3 5 2 1 1 3

u should use heap for this qn

I have done this question.
Here’s the code : https://ide.codingblocks.com/s/173363

Can you tell me the HEAP approach.
I am unable to think how to manage the frequencies along with the heap.

use the priority queue of type say pair which consists the value and its freq
you have to just implement the compare to method based on the freq.

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.