Kindly find error in the code
Your code is failing for the testcases like:
3
5 4
5 2 1 3 2
8 4
5 1 3 5 2 1 1 3
8 3
5 1 3 5 2 1 1 3
Your Output:
5 2 5 1 2 5 1 2 3 5 2 1 2 3
5 1 5 1 3 5 5 1 3 5 5 1 2 3 1 5 1 2 1 1 5 1 1 1 3 5
5 1 5 1 3 5 5 1 3 5 1 2 1 5 1 1 1 5 1 1 3
Expected Output:
5 2 5 1 2 5 1 2 3 5 2 1 3 5
5 1 5 1 3 5 5 1 3 5 1 2 3 1 5 2 3 1 5 2 3 1 3 5 2
5 1 5 1 3 5 5 1 3 5 1 2 1 5 2 1 5 2 1 3 5
Hope, this would help.
Give a like if you are satisfied.
I got the solution using vector approach as given in gfg. But I am unable to get the solution using priority queue. Kindly what changes should I make in previous code.
Sure @sr30,
For a heap, you have to implement a simple logic:
NOTE:
In case of priority queues its comparator is supposed to do the opposite of what you want to do actually, so when you are returning the bigger element it keeping them arranged in the opposite order that is increasing order rather than decreasing order
Hope, this would help.
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.