JAVA||Monotonic Stack
Please upvote if you find it useful! Thank you so much!!\n\n\nclass Solution {\n    public int[] maxNumber(int[] nums1, int[] nums2, int k) {\n        int len1 
Please upvote if you find it useful! Thank you so much!!\n\n```\nclass Solution {\n    public int[] maxNumber(int[] nums1, int[] nums2, int k) {\n        int len1 = nums1.length, len2 = nums2.length;\n        int[] res = new int[k];\n        int[] tempRes = null;\n        \n        // enumerate all the possible ways to construct an array with len k from two arrays\n        // the length of the res is k \n        // we assume that we pick k1 numbers from nums1, therefore we pick (k - k1) numbers\n        // from nums2. The possible range of k1 is from Math.max(0, k-len2)\n        // to Math.min(len1, k);\n        for(int k1 = Math.max(0, k-len2); k1 <= Math.min(len1, k); k1++){\n            int[] num1Max = findMaxSubsequence(nums1, k1);\n            int[] num2Max = findMaxSubsequence(nums2, k - k1);\n            tempRes = merge(num1Max, num2Max);\n            if(isGreater(tempRes, 0, res, 0)){\n                res = tempRes;\n            }\n        }\n        return res;\n    }\n    \n    // find the largest number that can be constructed from two arrays\n    private int[] merge(int[] nums1, int[] nums2){\n        int[] res = new int[nums1.length + nums2.length];\n        int p1 = 0, p2 = 0, p3 = 0;\n        \n        while(p3 < res.length){\n            res[p3++] = isGreater(nums1, p1, nums2, p2) ? nums1[p1++] : nums2[p2++];     \n        }\n        return res;\n    }\n    \n    private boolean isGreater(int[] nums1, int p1, int[] nums2, int p2){\n        while(p1 < nums1.length && p2 < nums2.length){\n            if(nums1[p1] > nums2[p2]){\n                return true;\n            }else if(nums1[p1] < nums2[p2]){\n                return false;\n            }\n            p1++;\n            p2++;\n        }\n        return p1 != nums1.length;\n    }\n    \n    // this subroutine is similar to leetcode 1673\n    private int[] findMaxSubsequence(int[] num, int len){\n        if(num.length == len){return num;}\n        \n        int[] stack = new int[len];\n        int top = -1;\n        int canRemoveCnt = num.length - len;\n        \n        for(int i = 0; i < num.length; i++){\n            int curNum = num[i];\n            \n            while(top >= 0 && canRemoveCnt > 0 && curNum > stack[top]){\n                top--;\n                canRemoveCnt--;\n            }\n            \n            if(top + 1 < stack.length){\n                stack[++top] = curNum;     \n            }else{\n                canRemoveCnt--;\n            }\n        }\n        \n        return stack;\n    }\n}\n```
[]