Top k most frequent number in a stream

i am uanble to do this question.
pls tell the code.

Refer this.

pls tell in the form of a code

Dry run this and check. The approach is same as i have explained in the above link.