Form Smallest Number From Two Digit Arrays

Given two arrays of unique digits nums1 and nums2, return the smallest number that contains at least one digit from each array.

Example 1
Inputnums1 = [4,1,3], nums2 = [5,7]
Output15
The number 15 contains the digit 1 from nums1 and the digit 5 from nums2, and it can be proven that 15 is the smallest possible number.
Example 2
Inputnums1 = [3,5,2,6], nums2 = [3,1,7]
Output3
The number 3 contains the digit 3 which exists in both arrays.

Constraints

  • 1 <= nums1.length, nums2.length <= 9
  • 1 <= nums1[i], nums2[i] <= 9
  • All digits in each array are unique.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate