Top k most frequent numbers in a stream

I am not able to do this question. I know that this question is to be done using hashmaps by storing the frequencies of each element in the array. After this I am not able to do it.

I even referred to Geeks for Geeks but I am not able to understand there. Please help !!

@avijuneja2007, i will suggest you to try this question using bruteforce first , and then try to optimize your solution using hashmap , i will suggest you to not directly jump to the most optimized method but instead start from bruteforce and then keep optimizing your solution as much as u can. the thing is i can explain you the solution directly and it might not make sense to you right now , instead first solve yourself and then ask me doubt in any specific part you are having problem so you will understand why this is done

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.