I don’t know what should be the output format if there is no intersecting element. I guess that is the first test case, because when I print blank for the above case, it shoes no output on submitting. I have tried printing ---- [], [ ] but it still doesn’t pass. Can some body tell me what is wrong?
#include<bits/stdc++.h>
using namespace std;
int main() {
int N;
cin>>N;
int A[N], B[N];
vector <int> C;
for (int i=0; i<N; i++)
cin>>A[i];
for (int i=0; i<N; i++)
cin>>B[i];
for (int i=0; i<N; i++) {
for (int j=i; j<N; j++) {
if (A[i]==B[j]) {
C.push_back(A[i]);
B[j] = -B[j];
break;
}
}
}
sort (C.begin(), C.end());
cout<<"[";
for (int i=0; i<C.size(); i++) {
if (i!=C.size()-1)
cout<<C[i]<<", ";
else
cout<<C[i];
}
cout<<"]";
return 0;
}