Hello Professionals,
I was taking a test online coding challenge in a website. They provide me 2 program. I had done a program and second one is below.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution{
/*
* Complete the function below.
*/
/* Write your custom functions here */
static void mergeArray(int []a, int []b, int M ){
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int _a_cnt = 0;
int[] _a = new int[100001];
int[] _b = new int[200002];
try {
_a_cnt = sc.nextInt();
}catch (Exception e) {
System.out.println("Here: " + e.getMessage());
}
for( int i = 0;i < _a_cnt;i++ ){
_a[i] = sc.nextInt();
}
for( int i = 0;i < _a_cnt;i++ ){
_b[i] = sc.nextInt();
}
mergeArray(_a ,_b,_a_cnt);
for( int i = 0;i < 2 * _a_cnt;i++ ){
System.out.print(_b[i] + " ");
}
}
}
In my understanding we need to write a piece of code for merge two array ( that already defined there like int []a, int []b, int M) and we should return it to main program. Here is my question how can we merge that two array and return it? Is there any technique to handle memory reference ( Like C# out,ref keyword ) in java?
Rule : You should not modify main function.
Here is some output:
Sample Input:
a = {3,5,6,9,12,14,18,20,25,28}
b = {30,32,34,36,38,40,42,44,46,48 }
Expected output :
{3,5,6,9,12,14,18,20,25,28,30,32,34,36, 38,40,42,44,46,48}