Median of sorted array code submission doubt

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;

}

hi @snehacpcb_6a154f5c45187387,
here test cases are faulty so u can leave it

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.