Difficulty in understanding the question

Please elaborate the question , I could not understand it properly

Sample Input

1
5 2
5 1 3 5 2

Sample Output

5 1 5 1 3 5 1 5 1

In case you are not understanding the output format:

5 comes : print( { 5 } )
1 comes : print( { 1,5 } )
3 comes : print( { 1,3 } ) , all three have same frequency so taking smaller 2.
5 comes : print( { 5,1 } ) , now 5 has max frequency.
2 comes : print( { 5,1 } )

Final output : 5, 1 5, 1 3, 5 1, 5 1.

Refer this https://www.geeksforgeeks.org/find-top-k-or-most-frequent-numbers-in-a-stream/

For heap based approach, read this discussion Top k most frequent in a stream of integers