Java Self-explanatory Neat Code
The final result res[] would be merged from res1[] and res2[], such that res1[] is max subsequence of nums1 of length ki, then res2[] is max subsequence of nums
The final result res[] would be merged from res1[] and res2[], such that res1[] is max subsequence of nums1 of length ki, then res2[] is max subsequence of nums2 with length k - ki.\nTo get max subsequence of length cnt, we use stack.\nTo do with merging and update final result, we use util method greater().\n```\n    public int[] maxNumber(int[] nums1, int[] nums2, int k) {\n        int[] result = new int[k];\n        \n        for (int ki = Math.max(0, k - nums2.length); ki <= Math.min(k, nums1.length); ki++) {\n            int[] res1 = getMaxSubsequence(nums1, ki); // ki < nums1.length\n            int[] res2 = getMaxSubsequence(nums2, k - ki); // k - ki < nums2.length\n            int[] resTmp = new int[k];\n            int p1 = 0, p2 = 0, pt = 0;\n            while (p1 < res1.length || p2 < res2.length) {\n                resTmp[pt++] = isGreater(res1, p1, res2, p2) ? res1[p1++] : res2[p2++];\n            }\n            if (!isGreater(result, 0, resTmp, 0)) {\n                result = resTmp;\n            }\n        }\n        return result;\n    }\n    \n    private int[] getMaxSubsequence(int[] nums, int cnt){\n        Stack<Integer> stack = new Stack<>();\n        int remain = cnt;\n        for (int i = 0; i < nums.length; i++) {\n            while (!stack.isEmpty() && stack.peek() < nums[i] && nums.length - 1 - i >= remain) {\n                stack.pop();\n                remain++;\n            }\n            if (remain > 0) {\n                stack.push(nums[i]);\n                remain--;\n            }\n        }\n        int[] maxSub = new int[cnt];\n        int mi = maxSub.length - 1;\n        while (!stack.isEmpty()) {\n            maxSub[mi--] = stack.pop();\n        }\n        return maxSub;\n    }\n    \n    private boolean isGreater(int[] nums1, int p1, int[] nums2, int p2) {\n        for (; p1 < nums1.length && p2 < nums2.length; p1++, p2++) {\n            if (nums1[p1] > nums2[p2]) {\n                return true;\n            }\n            if (nums1[p1] < nums2[p2]) {\n                return false;\n            }\n        }\n        return p1 != nums1.length;\n    }\n```
[]