Can you use a max heap? Donot forget to compare on the when then val is pushed, which will be usefull if there multiple values with same max frequency.