someone please elaborate the quesion with one more example
K most frequent numbers
Hey Divyansh, problem statement is pretty simple you are supposed to print top k numbers sorted by frequency when input stream has included k distinct elements, else need to print all distinct elements sorted by frequency. If frequency of two numbers are same then print them in increasing order.
For eg.
input:
8 3
5 1 3 5 2 1 1 3
output:
5 1 5 1 3 5 5 1 3 5 1 2 1 5 2 1 5 2 1 3 5
explaination :
when input is 7
output : 7
as we have only this element till now
when input is 1
output : 1 7
as we have 2 elements 1 and 7 so we are supposed to print them in sorted order.
when input is 3
output : 1 3 7
as we have 3 elements 1 7 and 3 so we are supposed to print them in sorted order.
when input is 7
output : 7 1 3
as we have 4 elements 1 7 7 3, now 7’s frequency is 2, 1’s frequency is 1,'3s frequency is 1, so we first print the number with highest frequency i.e 7 and then others are to printed in sorted order i.e. 1 3.
when input is 2
output : 7 1 2
as we have 5 elements 1 7 7 3 2, now 7’s frequency is 2, 1’s frequency is 1,3’s frequency is 1,2’s frequency is 1, so we first print the number with highest frequency i.e 7 and then others are to printed in sorted order i.e. 1 2 3, but as we have to print only k (3 in this case) elements so, we print 7 1 2.
when input is 1
output : 1 7 2
as we have 6 elements 1 1 7 7 3 2, now 7’s frequency is 2, 1’s frequency is 2,3’s frequency is 1,2’s frequency is 1, so we first print the number with highest frequency , now 7 and 1 has same frequency so we print them in sorted order as 1 7 and then others are to printed in sorted order i.e. 2 3, but as we have to print only k (3 in this case) elements so, we print 1 7 2.
when input is 1
output : 1 7 2
as we have 7 elements 1 1 1 7 7 3 2, now 7’s frequency is 2, 1’s frequency is 3 ,3’s frequency is 1,2’s frequency is 1, so we first print the number with highest frequency so 1 7 and then others are to printed in sorted order i.e. 2 3, but as we have to print only k (3 in this case) elements so, we print 1 7 2.
when input is 3
output : 1 3 7
as we have 8 elements 1 1 1 7 7 3 3 2, now 7’s frequency is 2, 1’s frequency is 3 ,3’s frequency is 2,2’s frequency is 1, so we first print the number with highest frequency so 1 3 7 and then others are to printed in sorted order i.e. 2, but as we have to print only k (3 in this case) elements so, we print 1 3 7.
Hope it helps you 
thanks a lot for helping me