/* P0013
 *
 * Merge Sorted Array
 * Given two sorted integer arrays A and B, merge B into A as one sorted array.
 *
 * Notes:
 * 1) Allow to use an auxilary array to store the restul? (O(M+N) space)
 * 2) What if the space complexity is O(1) (without additional storage)?
 */

public class P0013 {
    public static void merge(int[] a, int m, int[] b, int n) {
        // a.length = m + n
        // b.length = n
        int len = a.length;

        int i = m - 1, j = n - 1;
        for (int k = len - 1; k >= 0; k--) {
            if (i > 0 && j < 0)
                a[k] = a[i--];
            else if (i < 0 && j > 0)
                a[k] = b[j--];
            else {
                if (a[i] > b[j]) {
                    a[k] = a[i--];
                }
                else {
                    a[k] = b[j--];
                }
            }
        }
    }

    public static void print(int[] a, int len) {
        for (int i = 0; i < len; i++)
            System.out.print(a[i] + " ");

        System.out.println();
    }

    public static void main(String args[]) {
        int m = 5, n = 5;
    }
}

@@ -534,16 +534,17 @@
  if (i %3E
+=
  0 && j 
@@ -612,16 +612,17 @@
 0 && j %3E
+=
  0)%0A    
@@ -1099,16 +1099,264 @@
 , n = 5;
+%0A%0A        int%5B%5D tmp = %7B2, 5, 6, 9, 10%7D;%0A        int%5B%5D a = new int%5Bm + n%5D;%0A        for (int i = 0; i %3C m; i++)%0A            a%5Bi%5D = tmp%5Bi%5D;%0A%0A        int%5B%5D b = %7B1, 7, 8, 11, 15%7D;%0A%0A        P0013.merge(a, m, b, n);%0A        %0A        P0013.print(a, m + n);
 %0A    %7D%0A%7D

add test cases and fix