Skip to content

Instantly share code, notes, and snippets.

@mk6619
Created December 4, 2019 12:08
Show Gist options
  • Select an option

  • Save mk6619/a7529bf23319ef0f56139153c5f05026 to your computer and use it in GitHub Desktop.

Select an option

Save mk6619/a7529bf23319ef0f56139153c5f05026 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main() {
//code
int testCases;
cin>>testCases;
for(int i = 0 ; i < testCases; i++) {
int n,m;
cin>>n;
cin>>m;
int arr[n],arr_m[m];
for(int j =0 ; j < n ; j++) {
cin>>arr[j];
}
for(int j =0 ; j < m ; j++) {
cin>>arr_m[j];
}
int left = 0, right = 0;
while(left < n && right < m) {
if(arr[left] < arr_m[right]) {
cout << arr[left]<<" ";
left++;
} else {
cout << arr_m[right]<<" ";
right++;
}
}
if(left < n) {
for(int j = left ; j < n; j++) {
cout<<arr[j]<<" ";
}
}
if(right < m) {
for(int j = right ; j < m; j++) {
cout<<arr_m[j]<<" ";
}
}
cout << "\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment