Can anyone point out the flaw here? The logic I’m applying is correct imo(guessing by seeing correct submitted solutions of other users)
Solution: 1033661824 - CodeChef
@s4ga
your logic is not fully correct
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[n];
int mx=0;
set<int> s;
for(int i=0;i<n;i++)
{
cin>>a[i];
mx=max(a[i],mx);
}
for(int i=0;i<n;i++)
{
if(!s.count(a[i]))
{
s.insert(a[i]);
cout<<a[i];
}
else
cout<<mx;
cout<<" ";
}
cout<<endl;
}
return 0;
}
1 Like