#include
using namespace std;
int main() {
int n;
cin>>n;
int arr1[n],arr2[n],arr3[2*n];
for(int i=0;i<n;i++){
cin>>arr1[i];
}
for(int i=0;i<n;i++){
cin>>arr2[i];
}
int i=0,j=0,k=0;
while(i<n && j<n){
if(arr1[i]<arr2[j]){
arr3[k++]=arr1[i++];
}
else if(arr1[i]>arr2[j]){
arr3[k++]=arr2[j++];
}
else if(arr1[i]==arr2[j]){
arr3[k++]=arr1[i++];
arr3[k++]=arr2[j++];
}
}
while(i<n){
arr3[k++]=arr1[i++];
}
while(j<n){
arr3[k++]=arr2[j++];
}
int median=(arr3[n-1]+arr3[n])/2;
cout<<median;
return 0;
}
what is wrong in my code
Doubt in the question median of two sorted arrays
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.