Top k most frequent numbers in a stream

could u plz explain the sample input and output?

hi @tishya_goyal

input :
testcase=1
n=5 k = 2
arr[] = {5, 1, 3, 5, 2}
Output : 5 1 5 1 3 5 1 5 1

Explanation:

After reading 5, there is only one element 5 whose frequency is max till now.
so print 5.

After reading 1, we will have two elements 1 and 5 with the same frequency.
As 1, is smaller than 5 but their frequency is the same so we will print 1 5.

After reading 3, we will have 3 elements 1, 3 and 5 with the same frequency,
so print 1 3.

After reading element 5 since 5 has already occurred so we have now a
frequency of 5 as 2. So we keep 5 at the top and then rest of the element
with the same frequency in sorted order. So print, 1 5 1.

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course

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.