This code is for the question EQLIS of contest held on 19 January 2021.
It is not getting submitted for many test cases. I would like to know what is my mistake and what test cases I failing. I had tried lot of cases but still I am unhappy. Please check my code as below:-

#include <bits/stdc++.h>
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
long long n;
cin>>n;
int t=0;
if(n==2)
{
cout<<“NO”<<endl;
}
if(n!=2 && n%2==0)
{
t=1;
n = n-1;
}
if(n!=2)
{
vector v;
int b;
cout<<“YES”<<endl;
if(t==1)
{
cout<<n+1<<" ";
}
for(auto i=1;i<n;i=i+2)
{
v.push_back(i);
b=i;
}
if(n % 2 ==1)
{
v.push_back(n);
}
for(auto i=b+1;i>=2;i=i-2)
{
v.push_back(i);
}

```
for(auto i=0;i<v.size();i++)
{
cout<<v[i]<<" ";
}
cout<<endl;
}
}
return 0;
```

}

Just check following test case.

Test case:
2
4
6

Your Output:
YES
4 1 3 2
YES
6 1 3 5 4 2

Here for P: (4 1 3 2) longest increasing subsequence is (1,3) -->length 2
And for Pr: (2 3 1 4) longest increasing subsequence is (2,3,4) -->length 3.

Similarly for P: (6 1 3 5 4 2) lis is (1,3,4) → length 3.
And for Pr: (2 4 5 3 1 6) lis is (2,4,5,6) -->length 4.

slash_1
January 22, 2022, 3:26pm
#3
Can you tell why my answer is coming wrong plz ? Only two test-cases are passing i don’t know what wrong ?

#include<bits/stdc++.h>
using namespace std;

void rev(int i , int j , int ar[])
{
while(i<=j)
{
int temp = ar[i];
ar[i]= ar[j];
ar[j] = temp;
i++ , j–;
}
}

int main()
{
int t;
cin>>t;

```
while(t--)
{
int n;
cin>>n;
if(n == 2)
{
cout<<"NO"<<endl;
continue;
}
else
{
int ar[n];
for(int i=0;i<n;i++)
ar[i] = i+1;
cout<<"YES"<<endl;
if(n%2 != 0)
{
rev(n/2,n-1,ar);
for(int i = 0;i<n;i++)
cout<<ar[i]<<" ";
cout<<endl;
}
else
{
rev((n/2)-1,n-2,ar);
int temp = ar[(n/2)-1];
ar[(n/2)-1] = ar[n-1];
ar[n-1] = temp;
for(int i = 0;i<n;i++)
cout<<ar[i]<<" ";
cout<<endl;
}
}
}
```

}