Why is my code giving wrong answers? I find no error … I am using two pointers method.
int main()
{
int n; cin>>n;
int a[n],b[n],c[2*n];
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++) cin>>b[i];
for(int i=0,j=0,k=0;i<n or j<n;k++)
{
if((i<n and a[i]<b[j]) or (i!=n and j==n)) {c[k]=a[i]; i++;}
else if((j<n and a[i]>=b[j]) or (i==n and j!=n)) {c[k]=b[j]; j++;}
}
cout<<c[n-1]<<endl;
return 0;
}