Beginner Friendly Logic || Implementation in Java || Easy to understand
Algorithm:\nLet the arrays be arr1 and arr2\n1. Find the maximum length of arr1 which is less than or equal to k. i.e. n <= k. Create a maximum array for this s
Algorithm:\nLet the arrays be arr1 and arr2\n1. Find the maximum length of arr1 which is less than or equal to k. i.e. n <= k. Create a maximum array for this size using arr1.\n2.  Now left length is k - n. Lets call it m, which will be the length for arr2. Create maximum array of this size using arr2.\n\nNow comes the main logic\n\n3. Start a loop \n4. At every step decrease the size of arr1 by one and increment the size of arr2 by one, so that the sum of both sizes of array is equal to k   i.e.  n-- and m++\n\nSo the loop condition will become (m <= k && n>=0 && m <= arr2.length)\n\n5. Generate the array and merge both the arrays and store in the form of String for easy lexicographical comparison \n\n```\nclass Solution {\n\n    String str_ans;\n\n    int[] build(int org[], int size) {\n\n        // This function is for generating maximum array\n\n        int res[] = new int[size];\n        ArrayList<Integer> al = new ArrayList<>();\n\n        for (int i = 0; i < org.length; i++) {\n            al.add(i);\n        }\n\n        Collections.sort(al, (Integer a, Integer b) -> {\n            return org[b] - org[a];\n        });\n\n        int index = 0;\n        int count = 0;\n\n        Arrays.fill(res, -1);\n\n        while (count < size) {\n\n            int cur_ind = al.get(index++);\n            int smaller = org.length - cur_ind - 1;\n\n            for (int i = Math.max(0, size - smaller - 1); i < size; i++) {\n                if (res[i] == -1) {\n                    res[i] = cur_ind;\n                    count++;\n                    break;\n                }\n                if (res[i] > cur_ind) {\n                    break;\n                }\n            }\n        }\n\n        for (int i = 0; i < size; i++) {\n            res[i] = org[res[i]];\n        }\n\n        return res;\n    }\n\n    int[] merge(int arr1[], int arr2[]) {\n        int n = arr1.length;\n        int m = arr2.length;\n\n        int res[] = new int[n + m];\n\n        int ind1 = 0;\n        int ind2 = 0;\n\n        for (int i = 0; i < n + m; i++) {\n            int val1 = (ind1 >= n ? -1 : arr1[ind1]);\n            int val2 = (ind2 >= m ? -1 : arr2[ind2]);\n\n            if (val1 > val2) {\n                res[i] = val1;\n                ind1++;\n            } else if (val2 > val1) {\n                res[i] = val2;\n                ind2++;\n            } else {\n\n                // As both the values are equal find the first unequal element\n\n                int next_ind1 = ind1 + 1;\n                int next_ind2 = ind2 + 1;\n                while (next_ind1 < n && next_ind2 < m && arr1[next_ind1] == arr2[next_ind2]) {\n                    next_ind1++;\n                    next_ind2++;\n                }\n                if (next_ind1 == n) {\n                    res[i] = val2;\n                    ind2++;\n                } else if (next_ind2 == m) {\n                    res[i] = val1;\n                    ind1++;\n                } else if (arr1[next_ind1] > arr2[next_ind2]) {\n                    res[i] = val1;\n                    ind1++;\n                } else {\n                    res[i] = val2;\n                    ind2++;\n                }\n            }\n        }\n\n        return res;\n    }\n\n    String toString(int arr[]) {\n        StringBuilder sb = new StringBuilder();\n\n        for (int i = 0; i < arr.length; i++) {\n            sb.append(arr[i]);\n        }\n\n        return sb.toString();\n    }\n\n    public int[] maxNumber(int[] arr1, int[] arr2, int k) {\n        int ans[] = new int[k];\n\n        int n = Math.min(arr1.length, k);\n        int m = k - n;\n\n        str_ans = "";\n\n        while (m <= k && n >= 0 && m <= arr2.length) {\n\n            int cur_arr1[] = build(arr1, n);\n            int cur_arr2[] = build(arr2, m);\n\n            int res[] = merge(cur_arr1, cur_arr2);\n            String str_res = toString(res);\n\n            if (str_res.compareTo(str_ans) > 0) {\n                str_ans = str_res;\n            }\n\n            n--;\n            m++;\n        }\n\n        char c[] = str_ans.toCharArray();\n\n        for (int i = 0; i < k; i++) {\n            ans[i] = c[i] - \'0\';\n        }\n\n        return ans;\n    }\n}\n\n```\n\nThe solution can be improved by using better logic for removing and adding of element from both the arrays in the loop avoiding the complexity to build maximum array
[]