Getting wrong answer

@Jun18APP0112
please tell the logic behind the comparator you made so that i can understand what you are trying to do.

@Jun18APP0112 there is a problem in print function of your code.
let take an example :- 5 2 1 3 2 and k = 4
in this case when 2 is inserted again at last index then the top k elements should be :- 2 1 3 5
but your code will give :- 2 1 2 3 because you are inserting the ‘2’ again.

so for handling this you don’t need to change much in your code, just inside print function take care if that the element which has already occured while iterating the priority_queue, if come again then it will not counted.
You can use a set for checking if occured and vector to save the elements, and at last print the vector.

Feel free to ask if you face any difficulty in implementing this.

https://ide.codingblocks.com/s/208993 --please help i am getting that output but noother output

@Jun18APP0112 i have the done the above said changes in the code, check and tell me if there is any doubt. https://ide.codingblocks.com/s/210654

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.