someone please help me in figuring out why such thing is happening?
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t --)
{
int flag=0;
int n;
cin>>n;
int a[n];
int maxx=0;
map<int,int>m;
for(int i=0;i<n;i++)
{
cin>>a[i];
m[a[i]]++;
if(m[a[i]]>=3)
{
flag=1;
}
if (a[i]>maxx)
{
maxx=a[i];
}
}
if (flag==1)
{
cout<<"NO"<<endl;
continue;
}
if (m[maxx]>1)
{
cout<<"NO"<<endl;
continue;
}
cout<<"YES"<<endl;
for (auto i=m.begin();i!=m.end();i++)
{
cout<<i->first<<" ";
i->second-=1;
}
for (auto i=m.rbegin();i!=m.rend();i++)
{
if(i->second!=0)
cout<<i->first<<" ";
}
cout<<endl;
}
}