2 out of 4 testcases not passing

Kindly find the error. https://ide.codingblocks.com/s/210765
Another issue which I faced was that I had to empty the vector twice. I didn’t understand why it isn’t working when used only once.

Hello @sr30,

  1. Your output should be in a sorted order:
    Example:
    9
    1 20 8 4 2 12 10 14 22
    2 4 8 10 12 14 20 22 1
    1
    8 2
    Your Output:
    2 10 14 22 1

  2. No, you need not to empty it twice:

I have corrected it for point 2.

Hope, this would help.
Give a like if you are satisfied.

1 Like

Thanks for the help.
But as I had mentioned previously when i am clearing the vector by push_back method, I am getting an error, but using clear function is doing the job. For ur reference here is the code showing the wrng the output. Kindly tell why is it happening so.

Hello @sr30,

This is because of the way you have implemented the loop.
Your termination condition of the loop depends upon the size of ans and meanwhile, you are popping elements out of the ans.
Thus, leading to this issue.
I have corrected it:

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.