Description
Given two arrays of length m and n with digits 0-9, create the maximum number of length k ≤ m + n from digits of the two arrays, preserving their relative order.
Examples
Input:
nums1 = [3, 4, 6, 5], nums2 = [9, 1, 2, 5, 8, 3], k = 5Output:
[9, 8, 6, 5, 3]Explanation:
Maximum number of length 5.
Input:
nums1 = [1], nums2 = [1], k = 5Output:
[1]Explanation:
Edge case with a single-element array.
Input:
nums1 = [6, 7], nums2 = [6, 0, 4], k = 3Output:
[6, 7, 4]Explanation:
Three digits are needed total. Taking 6 and 7 from nums1 and 4 from nums2, then merging in decreasing order gives [7,6,4]. This is the lexicographically largest possible 3-digit number from these two arrays.
Constraints
- •
m == nums1.length - •
n == nums2.length - •
1 ≤ m, n ≤ 500 - •
0 ≤ nums1[i], nums2[i] ≤ 9