package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/create-maximum-number/
 */
public class Problem321 {
    public int[] maxNumber(int[] nums1, int[] nums2, int k) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem321 prob = new Problem321();
        System.out.println(Arrays.toString(prob.maxNumber(new int[]{3, 4, 6, 5}, new int[]{9, 1, 2, 5, 8, 3}, 5))); // [9, 8, 6, 5, 3]
        System.out.println(Arrays.toString(prob.maxNumber(new int[]{6, 7}, new int[]{6, 0, 4}, 5))); // [6, 7, 6, 0, 4]
        System.out.println(Arrays.toString(prob.maxNumber(new int[]{3, 9}, new int[]{8, 9}, 3))); // [9, 8, 9]
    }
}

@@ -202,35 +202,1748 @@
     
-// TODO%0A        return null
+char%5B%5D chars = maxNumber(nums1, nums2, k, 0, 0, %22%22, new String%5Bnums1.length + 1%5D%5Bnums2.length + 1%5D).toCharArray();%0A        int%5B%5D answer = new int%5Bchars.length%5D;%0A        for (int i = 0; i %3C answer.length; i++) %7B%0A            answer%5Bi%5D = chars%5Bi%5D - '0';%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static String maxNumber(int%5B%5D nums1, int%5B%5D nums2, int k, int i, int j, String accu,%0A                                    String%5B%5D%5B%5D memo) %7B%0A        if (accu.length() == k) %7B%0A            return accu;%0A        %7D%0A        long max = 0;%0A        if (i %3C nums1.length && j %3C nums2.length) %7B%0A            long a = Long.parseLong(maxNumber(nums1, nums2, k, i + 1, j + 1,%0A                accu + (nums1%5Bi%5D %3E nums2%5Bj%5D ? nums1%5Bi%5D : nums2%5Bj%5D), memo));%0A            long b = Long.parseLong(maxNumber(nums1, nums2, k, i + 1, j, accu, memo));%0A            long c = Long.parseLong(maxNumber(nums1, nums2, k, i + 1, j, accu + nums1%5Bi%5D, memo));%0A            long d = Long.parseLong(maxNumber(nums1, nums2, k, i, j + 1, accu, memo));%0A            long e = Long.parseLong(maxNumber(nums1, nums2, k, i, j + 1, accu + nums2%5Bj%5D, memo));%0A            max = Math.max(a, Math.max(b, Math.max(c, Math.max(d, e))));%0A        %7D else if (i %3C nums1.length) %7B%0A            long a = Long.parseLong(maxNumber(nums1, nums2, k, i + 1, j, accu, memo));%0A            long b = Long.parseLong(maxNumber(nums1, nums2, k, i + 1, j, accu + nums1%5Bi%5D, memo));%0A            max = Math.max(a, b);%0A        %7D else if (j %3C nums2.length) %7B%0A            long a = Long.parseLong(maxNumber(nums1, nums2, k, i, j + 1, accu, memo));%0A            long b = Long.parseLong(maxNumber(nums1, nums2, k, i, j + 1, accu + nums2%5Bj%5D, memo));%0A            max = Math.max(a, b);%0A        %7D%0A        return Long.toString(max)
 ;%0A  
@@ -2291,16 +2291,16 @@
 , 0, 4%5D%0A
-
         
@@ -2402,16 +2402,133 @@
 , 8, 9%5D%0A
+        System.out.println(Arrays.toString(prob.maxNumber(new int%5B%5D%7B9, 8, 7%7D, new int%5B%5D%7B1, 2%7D, 4))); // %5B9, 8, 7, 2%5D%0A
     %7D%0A%7D%0A

Update problem 321