Top k most frequent element in a stream

Is my logic correct whats the problem in my code