133. Create Maximum Number

HardArrayArray

Given two arrays of single digits nums1 and nums2 and integer k, create the maximum number of length k using digits from both arrays while preserving relative order within each array. Return it as a digit string. Input: '[nums1], [nums2], k'.

Input: '[nums1], [nums2], k'.

Output: Digit string of length k.

Examples

Example 1
Input: [3,4,6,5], [9,1,2,5,8,3], 5
Output: "98653"
Explanation: Max number of length 5.
Example 2
Input: [6,7], [6,0,4], 5
Output: "67604"
Explanation: Length-5 max.
Example 3
Input: [3,9], [8,9], 3
Output: "989"
Explanation: Length-3 max.

Constraints

Asked by

FlipkartGoogleOracleBloombergMicrosoftAmazon
Solve this problem in the editor →