Java Simple Solution || Monotonic Stack || Merge || All Combinations
class Solution {\n    \n    public int[] largeNum(int[] nums,int k){\n        int n = nums.length;\n        Stack stack = new Stack<>();\n        for(int i = 0;
class Solution {\n    \n    public int[] largeNum(int[] nums,int k){\n        int n = nums.length;\n        Stack<Integer> stack = new Stack<>();\n        for(int i = 0;i < n;i++){\n            \n            while(stack.size() > 0 && stack.peek() < nums[i] && k - stack.size() <= n - i - 1){\n                stack.pop();\n            }\n            \n            stack.push(nums[i]);\n        }\n        \n        int[] ans = new int[stack.size()];\n        int ptr = stack.size() - 1;\n        \n        while(!stack.isEmpty()){\n            ans[ptr--] = stack.pop();\n        }\n        return ans;\n    }\n    \n    boolean isGreater(int[] max1,int[] max2,int i,int j){\n        \n        while(i < max1.length || j < max2.length){\n            \n            if(i >= max1.length) return false;\n            else if(j >= max2.length) return true;\n            else if(max1[i] < max2[j]) return false;\n            else if(max1[i] > max2[j]) return true;\n            else{\n                i++;\n                j++;\n            }\n        }\n        \n        return true;\n        \n    }\n    \n    \n    \n    public int[] maxNumber(int[] nums1, int[] nums2, int k) {\n        \n        int[] ans = new int[k];\n        \n        for(int i = 0;i <= k;i++){\n            \n            if(i > nums1.length || k - i > nums2.length) continue;\n            \n            int[] max1 = largeNum(nums1,i);\n            int[] max2 = largeNum(nums2,k - i);\n            \n            //merge\n            int a = 0;\n            int b = 0;\n            int[] temp = new int[k];\n            int ptr = 0;\n            while(a < max1.length || b < max2.length){\n                if(ptr >= k){\n                    break;\n                }\n                if(a >= max1.length) temp[ptr++] = max2[b++];\n                else if(b >= max2.length) temp[ptr++] = max1[a++];\n                else if(max1[a] < max2[b]) temp[ptr++] = max2[b++];\n                else if(max1[a] > max2[b]) temp[ptr++] = max1[a++];\n                else{\n                    if(isGreater(max1,max2,a,b)){\n                        temp[ptr++] = max1[a++];\n                    }\n                    else{\n                        temp[ptr++] = max2[b++];\n                    }\n                }\n            }\n            // for(int j = 0;j < k;j++){\n            //     System.out.print(temp[j] + " ");\n            // }\n            //System.out.println();\n            if(isGreater(temp,ans,0,0)){\n                System.out.print("In");\n                ans = temp;\n            }\n            \n        }\n        \n        return ans;\n    }\n}
['Monotonic Stack']