Wrong answer in "ICM002"

why am i getting wrong answer for this code :
https://www.codechef.com/viewsolution/44704509

also if the link not working :
#include <bits/stdc++.h>
using namespace std;
#define lli long long int

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli testcase;
cin>>testcase;
//enter the remaining constrains

lli n;
lli counter1;
while(testcase--)
{
	cin>>n;
	counter1 = 0;
	lli arr[n];
	for(lli i=0;i!=n;i++)
    cin>>arr[i];
	if(n==1)
	cout<<"YES\n0\n";
	else
	{
	for(lli i=1;i!=n;i++)
	{
	    if(arr[i-1]==(arr[i]+1))
	    counter1++;
	}
	if(counter1==(n-1))
	cout<<"YES\n0\n";
	else if(counter1==(n-2))
	cout<<"YES\n1\n";
	else
	cout<<"NO\n";
	}

}
return 0;

}
Please let me know And I will work on it Thank you !!

Did run your code on the samples ?

your sorting check method is wrong, array is not in continuous form array has any value greater than n also. and you have to update your code further for AC solution

check for test case:
4
2 1 2 2

Your output: NO
Correct :YES,1

I think I miss understood the question. Thank you for your replies