How we print -1

how we print -1. since we check whether frequency of character is greater than 1. then we pop 1 character
and frequency become 1 then we print.
so queue can never get empty.

@Adityakumar3112,
No, after toping the element, we don’t decrease its frequency. Thus if in a situation, when all frequencies are greater than 1, we will pop till queue is empty and then print -1.

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.