Top k most frequent number in a string

other than using maps and set is there any other approach to solve this question?

Yes
You can use a heap of pairs where you keep the most frequent number on the top