I am finding the error for nearly two days but i am still not able to plz help
here is the link for my solution CodeChef: Practical coding for everyone
we dont have to sort that array …
try using stack without sorting the array 
can you tell which test case is failing it will be very beneficial thanks
Check this test case (this could be the smallest test case your code fails).
Input
1
18
20 10 4 8 15 17 20 17 4 10 1 3 2 5 20 9 11 17
Expected Output
2
Your Output
-1
N can not be 1 in this question btw thanks
Thank you so much bro you really good I was unable to find cause it was so long test case
We’ll try finding smaller test cases 
no no i will debug now thanks
Try this
1
19
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
oh the constraint thank you…
good luck
lol thanks
After everything you’ve done, you should read the editorial. It will help you in approaching a problem in a better way.
I have already done the way in the editorial but i was wondering why I am wrong, Is it necessary to solve the problem by the way given in the ediotrials?