My issue
why this solution is not acceptable if answer is validate situation
include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t–){
int n;
cin>>n;
vectorv(n,0);
for(int i=0;i<n;i++)cin>>v[i];
sort(v.begin(),v.end());
vectornums(n,0);
unordered_map<int,int>mp;
bool chk = 0;
for(int i =0,j=0 ;i<n;i++){
mp[v[i]] ++;
if(mp[v[i]]>n/2 + n%2)chk =1;
if(j >=n){
j =1;
}
nums[j] = v[i];
j+=2;
}
if(chk){
cout<<-1;
}else {
for(int i=0;i<n;i++)cout<<nums[i]<<" ";
}
cout<<endl;
}
return 0;
}
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
vector<long long >v(n,0);
for(int i=0;i<n;i++)cin>>v[i];
sort(v.begin(),v.end());
vector<long long >nums(n,0);
unordered_map<int,int>mp;
bool chk = 0;
for(int i =0,j=0 ;i<n;i++){
mp[v[i]] ++;
if(mp[v[i]]>n/2 + n%2)chk =1;
if(j >=n){
j =1;
}
nums[j] = v[i];
j+=2;
}
if(chk){
cout<<-1;
}else {
for(int i=0;i<n;i++)cout<<nums[i]<<" ";
}
cout<<endl;
}
return 0;
}
Problem Link: CONCUSSIVE Problem - CodeChef