Largest Number From Two Dispatch Queues
Two ordered queues of single digits feed a dispatch tag. You must pick exactly k digits across both queues, preserving each queue's relative order, to form the largest possible number.
Problem
Given two integer arrays nums1 and nums2 representing digits (0–9) of two numbers and an integer k, create the maximum number of length k from digits of the two arrays. The relative order of digits taken from the same array must be preserved. Return an array of the k digits of the maximum number.
Input
Two digit arrays nums1, nums2 and an integer k with k <= len(nums1) + len(nums2).
Output
An array of k digits representing the maximum number.
Constraints
- 0 <= nums1.length, nums2.length <= 500
- 0 <= nums1[i], nums2[i] <= 9
- 1 <= k <= nums1.length + nums2.length
Examples
Example 1
Input
nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5
Output
[9,8,6,5,3]
Take 6,5 from the first and 9,8,3 from the second, merged greedily.
Example 2
Input
nums1 = [6,7], nums2 = [6,0,4], k = 5
Output
[6,7,6,0,4]
All digits used; merged to maximize.