You are viewing a single comment's thread. Return to all comments →
This is the shortest way (as per my knowledge).
However, there is an error.
when [q == 2], before doing cnt[freq[q]]-=1, you should check if cnt[freq[q]] > 0. Otherwise, you might make it negative.