I am using the below code to solve the problem but 3 test cases are not passing. Since I am unable to see what the test cases are I need guidance for the correct logic. (I have used the second method from the hints)
#include
#include
using namespace std;
void findMedian(vector &arr1, vector &arr2, int n){
vector merged;
int i=0, j=0;
while(i<n && j<n){
if(arr1[i]<arr2[j]){
merged.push_back(arr1[i]);
i++;
}else{
merged.push_back(arr2[j]);
j++;
}
}
while(i<n){
merged.push_back(arr1[i]);
i++;
}while(j<n){
merged.push_back(arr2[j]);
j++;
}
cout<<merged[n-1];
}
int main() {
int n;
cin>>n;
vector arr1(n),arr2(n);
for(int i=0;i<n;i++){
cin>>arr1[i];
}
for(int j=0;j<n;j++){
cin>>arr2[j];
}
findMedian(arr1,arr2,n);
}