divide to three subproblem solution, beat 98%
subproblem1: \nget the largest k numbers when keeping the relative order\n\nsubproblem2: \nmerge two arrays which are from subproblem1.\n\nsubproblem3: \ncompar
subproblem1: \nget the largest k numbers when keeping the relative order\n\nsubproblem2: \nmerge two arrays which are from subproblem1.\n\nsubproblem3: \ncompare two arrays.\n\n```\npublic class Solution {\n    public int[] maxNumber(int[] nums1, int[] nums2, int k) {\n        int len1 = nums1.length;\n        int len2 = nums2.length;\n        int[] result = new int[k];\n        if(len1+len2 < k) {\n            return result;//bad case\n        }else if(len1+len2 == k){\n            result = mergeTwoArrays(nums1, nums2, k);//edge case\n        }else{\n            for (int i = 0; i <= k; i++) {\n                if(i<=len1 && (k-i)<=len2){\n                    int[] maxNumbers1 = maxNumberOfSingleArray(nums1, i);\n                    int[] maxNumbers2 = maxNumberOfSingleArray(nums2, k - i);\n                    int[] maxNumbers = mergeTwoArrays(maxNumbers1, maxNumbers2, k);\n                    if (compareTwoArrays(maxNumbers, 0, result, 0)) result = maxNumbers;\n                }\n            }\n        }\n        return result;\n    }\n    \n    private int[] mergeTwoArrays(int[] nums1, int[] nums2, int k) {\n        int[] result = new int[k];\n        int idx1 = 0, idx2 = 0;\n        int idx = 0;\n        while(idx < k){\n            //check the two remain arrays to see which one is larger.\n            if(compareTwoArrays(nums1, idx1, nums2, idx2)){\n                result[idx] = nums1[idx1++];\n            }else{\n                result[idx] = nums2[idx2++];\n            }\n            idx++;\n        }\n        return result;\n    }\n    \n    //get the largest k numbers when keeping the relative order\n    private int[] maxNumberOfSingleArray(int[] nums, int k){\n        int[] result = new int[k];\n        if(k == 0) return result;\n\n        int len = nums.length;\n        int idx = 0;\n        for(int i = 0; i < len; i++){\n            while((len-i-1) + (idx+1) > k && idx>0 && nums[i] > result[idx-1]) idx--;\n            if(idx < k) result[idx++] = nums[i];\n        }\n        return result;\n    }\n    \n    //compare two arrays at the "start" index\n    public boolean compareTwoArrays(int[] nums1, int startIdx1, int[] nums2, int startIdx2) {\n        int len1 = nums1.length - startIdx1;\n        if(len1 <= 0) return false;\n        int len2 = nums2.length - startIdx2;\n        if(len2 <= 0) return true;\n        int len = Math.max(len1, len2);\n        for (int i = 0; i< len; i++) {\n        \tint digit1 = startIdx1 + i < nums1.length ? nums1[startIdx1 + i] : 0;\n        \tint digit2 = startIdx2 + i < nums2.length ? nums2[startIdx2 + i] : 0;\n        \tif(digit1 != digit2){\n        \t    return digit1 > digit2;\n        \t}\n        }\n        return true;//equal, choose either one is ok\n    }\n}\n````
[]