Problem:

Start with two arrays of strings, A and B, each with its elements in alphabetical order and without duplicates. Return a new array containing the first N elements from the two arrays. The result array should be in alphabetical order and without duplicates. A and B will both have a length which is N or more. The best "linear" solution makes a single pass over A and B, taking advantage of the fact that they are in alphabetical order, copying elements directly to the new array.

mergeTwo({"a", "c", "z"}, {"b", "f", "z"}, 3) → {"a", "b", "c"}
mergeTwo({"a", "c", "z"}, {"c", "f", "z"}, 3) → {"a", "c", "f"}
mergeTwo({"f", "g", "z"}, {"c", "f", "g"}, 3) → {"c", "f", "g"}

Solution:

public String[] mergeTwo(String[] a, String[] b, int n) {
String out[] = new String[n];
int aindex =0, bindex=0;
for(int i=0; i<n; i++)
{
int cmp = a[aindex].compareTo( b[bindex] );
if(cmp<=0)
{
out[i] = a[aindex++];
if(cmp == 0) bindex++;
}
else
{
out[i] = b[bindex++];
}
}
return out;
}

1. public String[] mergeTwo(String[] a, String[] b, int n) {
String[] str=new String[n];
int count=0;
int acount=0;
int bcount=0;
while(count0){
str[count]=b[bcount];
count++;
bcount++;
}
else if(x<0){
str[count]=a[acount];
count++;
acount++;
}
else if(x==0){
str[count]=a[acount];
acount++;
bcount++;
count++;
}
}
return str;
}

1. there is no description for x..

2. public String[] mergeTwo(String[] a, String[] b, int n) {
int pos =0, val =0, i =0, j =0;
String[] array = new String[n];
while (pos < array.length){
val = a[i].compareTo(b[j]);
if (val == 0){
array[pos++] = a[i];
i++;
j++;
}else if (val < 0){
array[pos++] = a[i];
i++;
}else if (val > 0){
array[pos++] = b[j];
j++;
}
}
return array;
}

3. public Strin[] mergeTwo(String[] a,String[] b,int n)
{
HashSet set=new HashSet;
for(int i=0;i<a.length;i++)
for(int i=0;i<b.length;i++)
String str[]=set.toArray(new String[set.size()]);
String strArr[]=new String[n];
for(int i=0;i<n;i++)
strArr[i]=str[i];
return strArr;
}

4. public Strin[] mergeTwo(String[] a,String[] b,int n)
{
HashSet set=new HashSet;
for(int i=0;i<a.length;i++)
for(int i=0;i<b.length;i++)
String str[]=set.toArray(new String[set.size()]);
String strArr[]=new String[n];
for(int i=0;i<n;i++)
strArr[i]=str[i];
return strArr;
}

5. public Strin[] mergeTwo(String[] a,String[] b,int n)
{
HashSet set=new HashSet;
for(int i=0;i<a.length;i++)
for(int i=0;i<b.length;i++)
String str[]=set.toArray(new String[set.size()]);
String strArr[]=new String[n];
for(int i=0;i<n;i++)
strArr[i]=str[i];
return strArr;
}

6. i didn't readthath A and B has the same length. My solution in that case...
public String[] mergeTwo(String[] a, String[] b, int n) {

String [] x =new String[n];
String [] y = new String [a.length +b.length];

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

}

for (int i=0; i<b.length; i++) {
y[a.length +i] = b[i];

}

Arrays.sort(y);
for (int q=0; q<y.length-1; q++) {
if(y[q].equals(y[q+1])) {
y[q]="zzzzzzz";
}
}
Arrays.sort(y);

for(int w=0; w<n; w++) {
x[w]=y[w];
}
return x;

7. public String[] mergeTwo(String[] a, String[] b, int n)
{
ArrayList merge = new ArrayList();
String[] result = new String[n];
for(int s = 0; s < a.length; s++)
{
}
for(int x = 0; x < b.length; x++)
{
}
Collections.sort(merge);
for(int r = 0; r < merge.size() - 1; r++)
{
if(merge.get(r).equals(merge.get(r + 1)))
{
merge.remove(r);
}
}
for(int i = 0; i < n; i++)
{
result[i] = merge.get(i);
}
return result;
}

1. ArrayList with triangle brackets are removed for some reason.

2. public String[] mergeTwo(String[] a, String[] b, int n)
{
ArrayList merge = new ArrayList();
String[] result = new String[n];
for(int s = 0; s < a.length; s++)
{
}
for(int x = 0; x < b.length; x++)
{
}
Collections.sort(merge);
for(int r = 0; r < merge.size() - 1; r++)
{
if(merge.get(r).equals(merge.get(r + 1)))
{
merge.remove(r);
}
}
for(int i = 0; i < n; i++)
{
result[i] = merge.get(i);
}
return result;
}

8. public String[] mergeTwo(String[] a, String[] b, int n) {
String[] res = Arrays.copyOfRange(a, 0, n);
for(int i = 0; i < b.length; i++){
for(int y = 0 ; y < res.length; y++){
if(y > 0 && b[i].compareTo(res[y-1]) == 0) break;
if(b[i].compareTo(res[y]) < 0){
String repl = res[y];
res[y] = b[i];
if(y+1 < res.length) res[y+1] = repl;
break;
}
}
}
return res;
}

9. public String[] mergeTwo(String[] a, String[] b, int n) {
List list = new ArrayList();
for(int i = 0;i<n;i++){
}
Collections.sort(list);
return list.subList(0,n).toArray(new String[n]);
}

10. public String[] mergeTwo(String[] a, String[] b, int n) {
String[] arr = new String[n];

for (int i = 0, j = 0, arrPlace = 0 ; arrPlace < arr.length; ) {
char one = (char) Math.min(a[i].charAt(0), b[j].charAt(0));
arr[arrPlace] = "" + one;
arrPlace++;
if (a[i].charAt(0) < b[j].charAt(0)) i++;
else if (a[i].charAt(0) > b[j].charAt(0)) j++;
else {
i++;
j++;
}
}
return arr;
}