## Citigroup Interview Question

Solutions Architects**Country:**India

**Interview Type:**Written Test

arr1 = [0,1,2,3, 4,5,6,7]

arr2 = [-1, 0,1,2,3]

arr = []

def mysort(arr1, arr2):

i = 0

j = 0

while i < len(arr1) or j < len(arr2):

if i < len(arr1) and j < len(arr2):

if arr1[i] < arr2[j]:

arr.append(arr1[i])

i += 1

elif arr2[i] < arr1[j]:

arr.append(arr2[j])

j += 1

elif arr1[i] == arr2[j]:

arr.append(arr1[i])

arr.append(arr2[j])

i += 1

j += 1

elif i < len(arr1):

arr.append(arr1[i])

i += 1

elif j < len(arr2):

arr.append(arr2[j])

j += 1

return arr

print(mysort(arr1, arr2))

#include <bits/stdc++.h>

using namespace std;

int main(){

int n, m;

cin >> n >> m;

int a[n], b[m];

for(int i=0; i<n; i++){

cin >> a[i];

}

for(int i=0; i<m; i++){

cin >> b[i];

}

int c[n+m];

int i = 0, j = 0, k = 0;

while(i < n+m){

if(j<n && k<m && a[j] < b[k]){

c[i] = a[j];

i++;

j++;

}

else if(j<n && k<m && a[j] >= b[k]){

c[i] = b[k];

i++;

k++;

}

else if(j==n-1 && k<m-1){

c[i] = b[k];

k++;

i++;

}

else{

c[i] = a[j];

j++;

i++;

}

}

for(int i=0; i<n+m; i++){

cout << c[i] << " ";

}

cout << endl;

return 0;

}

public int[] sort(int[] a, int[] b) {

int len = (a.length + b.length);

int[] result = new int[len];

for (int i = 0; i < a.length; i++) {

result[i] = a[i];

}

for (int j = 0; j < b.length; j++) {

result[a.length + j] = b[j];

}

for (int m = 0; m < (len - 1); m++) {

for (int k = 0; k < (len - 1); k++) {

if (result[k + 1] < result[k]) {

int tmp = result[k];

result[k] = result[k + 1];

result[k + 1] = tmp;

}

}

}

return result;

}

public int[] sort(int[] a, int[] b) {

int len = (a.length + b.length);

int[] result = new int[len];

for (int i = 0; i < a.length; i++) {

result[i] = a[i];

}

for (int j = 0; j < b.length; j++) {

result[a.length + j] = b[j];

}

for (int m = 0; m < (len - 1); m++) {

for (int k = 0; k < (len - 1 - m); k++) {

if (result[k + 1] < result[k]) {

int tmp = result[k + 1];

result[k + 1] = result[k];

result[k] = tmp;

}

}

}

return result;

}

- rasmiranjanbabu July 12, 2016