Not able to crack this question

please give some hint,how to store frequency,and how to think in such type of questions.

@Vikash
Since you need to sort first on the basis of frequency and then on the basis of value , make a heap of pairs of int.
Store the value in the first element of pair and its frequency in the second element.
Make a custom functor to sort according our given criteria and pass it to the priority queue. At every step , take an input , update its frequency in the heap or insert it if not already present and print the elements accordingly.
Using a priority queue is our best option as we require some sorting to be done .
Try this approach and let me know if you need some help with it.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.