Share my greedy solution
Many of the posts have the same algorithm. In short we can first solve 2 simpler problem\n\n1. Create the maximum number of one array \n2. Create the maximum nu
Many of the posts have the same algorithm. In short we can first solve 2 simpler problem\n\n1. Create the maximum number of one array \n2. Create the maximum number of two array using all of their digits.\n\nFor an long and detailed explanation see my blog [here][1].\n\nThe algorithm is O((m+n)^3) in the worst case. It runs in 22 ms.\n\n**Java**\n\n    public int[] maxNumber(int[] nums1, int[] nums2, int k) {\n        int n = nums1.length;\n        int m = nums2.length;\n        int[] ans = new int[k];\n        for (int i = Math.max(0, k - m); i <= k && i <= n; ++i) {\n            int[] candidate = merge(maxArray(nums1, i), maxArray(nums2, k - i), k);\n            if (greater(candidate, 0, ans, 0)) ans = candidate;\n        }\n        return ans;\n    }\n    private int[] merge(int[] nums1, int[] nums2, int k) {\n        int[] ans = new int[k];\n        for (int i = 0, j = 0, r = 0; r < k; ++r)\n            ans[r] = greater(nums1, i, nums2, j) ? nums1[i++] : nums2[j++];\n        return ans;\n    }\n    public boolean greater(int[] nums1, int i, int[] nums2, int j) {\n        while (i < nums1.length && j < nums2.length && nums1[i] == nums2[j]) {\n            i++;\n            j++;\n        }\n        return j == nums2.length || (i < nums1.length && nums1[i] > nums2[j]);\n    }\n    public int[] maxArray(int[] nums, int k) {\n        int n = nums.length;\n        int[] ans = new int[k];\n        for (int i = 0, j = 0; i < n; ++i) {\n            while (n - i + j > k && j > 0 && ans[j - 1] < nums[i]) j--;\n            if (j < k) ans[j++] = nums[i];\n        }\n        return ans;\n    }\n\n\n  [1]: http://algobox.org/create-maximum-number/
['Greedy', 'Java']