Not able to get any logic

Hii… I am not able to come up with proper logic… I have seen on GFG… But not able to understand proerly.
Kindly help.

hello @ashishnnnnn
the logic is simple .
we are using one vector of size (k+1 ) to keep track of top k frequent numbers so far.
a map to store frequency.

when u read a new number number its frequency get updated right? that means its position might get change in top k frequent vector.
so there we are using logic similar to insertion sort i.e we are finding the best position of current element for insertion. and then we are inserting it there by perfoming swaps
and then simply printing thr resulting vector

Are you talking about the approch mentioned in GFG…

yeah . . . . . . . . . . . . . . . . . .