Talentd
FleetCode

2605. Form Smallest Number From Two Digit Arrays

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

Example 1:

Input: nums1 = [4,1,3], nums2 = [5,7]
Output: 15
Explanation: The number 15 contains the digit 1 from nums1 and the digit 5 from nums2. It can be proven that 15 is the smallest number we can have.

Example 2:

Input: nums1 = [3,5,2,6], nums2 = [3,1,7]
Output: 3
Explanation: 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 company

Hints open one at a time

Hint 1
How many digits will the resulting number have at most?
Hint 2
The resulting number will have either one or two digits. Try to find when each case is possible.
5:56
Still stuck?Read 5 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def minNumber(self, nums1: List[int], nums2: List[int]) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
[4,1,3]
[5,7]
Input
[3,5,2,6]
[3,1,7]
Your code is saved on this device.Solution