# Help me in solving INCRDEC problem

### My code

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

int main(){
int t=0;int n=0;
cin>>t;
while(t--){
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
sort(arr,arr+n);
vector<int>l;
vector<int>r;
int f=0;
//(count(arr, arr + n, arr[i]) == 1
if(count(arr, arr + n, arr[n-1]) != 1){
cout<<"NO"<<endl;f=1;
}else{
int i=0;
while(i <= n-1){
if(count(arr, arr + n, arr[i]) == 1){
l.push_back(arr[i]);i++;
}else if(count(arr, arr + n, arr[i]) == 2){
l.push_back(arr[i]);
r.insert(r.begin(),arr[i]);
i+=2;
}else{
cout<<"NO"<<endl;f=1;break;
}
}
}

if(f==0){
cout<<"YES"<<endl;
for(auto j:l){
cout<<j<<" ";
}
for(auto j:r){
cout<<j<<" ";
}
cout<<endl;
}else{
f=0;
}

}
return 0;
}

``````

Problem Link: CodeChef: Practical coding for everyone

@dragon_warri0r
U are using count for each i which will lead to complexity of O(n^2) which will eventually provide u tle .
so to tackle this just count the freq of each element before hand and store it some data structure like map etc.