Recover the Sequence RECVSEQ

Anyone help me to find where my code is failing?
I’m getting the desired output for every test cases of my sense.
1
9
9 8 7 6 5 4 3 2 1
My Output:
1 2 3 4 5 6 7 8 9
Is this correct for the above test case?
My solution https://www.codechef.com/viewsolution/24746630

No your output is wrong
The correct output for your given test case would be:
9 8 7 6 5 4 3 2 1 i.e the sequence wasn’t changed at all.

As far as I can understand your code, you aren’t handling the case of n==4 explicitly(I am not sure of that).
According to me , the n==4 needs to be handled separately and for n>=5 count the difference between the terms and take the one with the maximum frequency.
Here’s the link to my code: https://www.codechef.com/viewsolution/24318103

Not quite sure… But was doubtful about this test case. Will change my code accordingly.

I have generalized for all values of n. It’s working in every single case. Try few of your’s and let me know if I m wrong.