Top k most frequent numbers in a stream

https://ide.codingblocks.com/s/252479 where is my code going wrong?

refer to this approach

in ur code u are not following the condition given in q

We basically need 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.