---
# System prepended metadata

title: Ruben Pardo Code Exercise
tags: [SUSE]

---

Exercise: You have two sorted arrays, A and B. A has a large enough buffer at the end to hold B. Write a method to merge B into A in sorted order.

```



public Int[] merged(Int[] a, Int[] b) {

  if(a.length == 0) {
      return b;
  } else if (b.length == 0) {
      return a;
  } else {
      Int[] merged = new Integer[];
      int pointMerged =0;
      int j=0;
      int i=0; 
      while( j < a.length){ 
       while( i< b.length) {
         if ( a[j] < b[i]) {
             merged[pointMerged] = a[j];
             pointMerged++;
             j++;
         } else if( a[j] > b[i]{
            merged[pointMerged] = b[i];
            pointMerged++;
            b++;
         } else {
            merged[pointMerged] = b[i];
            pointMerged++;
            merged[pointMerged] = a[j];
            pointMerged++;
            i++; 
            j++;
         }
      }
      }
  }
}


Code here
```