Please help, I’m unable to understand what the question is trying to say.
@sumonelse
the logic is print the number with highest distance between them first.
plzz refer my c++ code for better understanding
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[2*n];
map<int,int> mp;
vector<pair<int,int>> v;
for(int i=0;i<2*n;i++)
{
cin>>a[i];
if(!mp.count(a[i]))
{
mp[a[i]]=i;
}
else
{
mp[a[i]]=i-mp[a[i]];
}
}
for(auto x:mp)
{
v.push_back({x.second,x.first});
}
sort(v.rbegin(),v.rend());
for(auto x:v)
{
cout<<x.second<<" ";
}
cout<<endl;
}
}
Bro, can you please explain me the question. I am unable to understand it
.
@sumonelse
actually the questions states that U have given some array with 2*n elements with each element between 1 to N and each of them have frequency 2.
now u have to print some permutation of N such that If u iterate the permutation and keep the prefix elements and remove the rest then the difference between any of pair should not be greater than n;
like for 1 1 2 2 3 3
we can print 3 1 2.
so first we will keep 3 and delete the remaining .
the we will keep 3 and 1 and delete the remaining .
then we will keep 3 1 2 and delete the remaining.