
You are given two integer arrays, 'nums1' of length 'm' and 'nums2' of length 'n', which represent the digits of two numbers. You are also given an integer 'k'.
Your task is to create the lexicographically largest possible number of length 'k' by picking digits from the two given arrays. The relative order of digits taken from the same array must be preserved.
Return an array of 'k' digits that represents the answer.
The first line contains three space-separated integers: 'm' (length of nums1), 'n' (length of nums2), and 'k'.
The second line contains 'm' space-separated integers, representing the elements of array 'nums1'.
The third line contains 'n' space-separated integers, representing the elements of array 'nums2'.
Print 'k' space-separated integers representing the digits of the maximum number.
Lexicographically larger means that at the first position where two numbers differ, the number with the larger digit is considered greater. For example, [9, 8, 5] is lexicographically larger than [9, 7, 6].
The relative order of digits from the same source array must be maintained. For example, if you take 4 and 5 from [3, 4, 6, 5], they must appear in the order 4, 5 in the result.
4 6 5
3 4 6 5
9 1 2 5 8 3
9 8 6 5 3
To create the maximum number of length 5, we can try all combinations of taking `i` digits from `nums1` and `5-i` digits from `nums2`.
The optimal choice is to take 2 digits from `nums1` (the best subsequence is `[6, 5]`) and 3 digits from `nums2` (the best subsequence is `[9, 8, 3]`).
Merging these two subsequences `[6, 5]` and `[9, 8, 3]` to get the lexicographically largest result yields `[9, 8, 6, 5, 3]`.
2 3 5
6 7
6 0 4
6 7 6 0 4
Here, k = m + n, so we must use all digits from both arrays. The task simplifies to merging `[6, 7]` and `[6, 0, 4]` while preserving their internal order to create the largest number.
The expected time complexity is O(k * (m + n)).
m == nums1.length
n == nums2.length
1 <= m, n <= 500
0 <= nums1[i], nums2[i] <= 9
1 <= k <= m + n
Time limit: 1sec
The expected time complexity is O(k * (m + n)).