Date: 2026-06-06
Time: 16:54
form-smallest-number-from-two-digit-arrays/solution.pyThis file solves LeetCode 2605: Form Smallest Number From Two Digit Arrays. Given two arrays of unique single digits (1-9), it finds the smallest integer that contains at least one digit from each array. The file is self-contained: solution function + inline unit tests.
smallestnumberwithatleastonedigitfromeach_array(nums1, nums2) -> int — The core solver. It handles two distinct cases:
1. Common digit exists: If the arrays share any digit, the answer is simply the smallest shared digit (a single-digit number always beats a two-digit number).
2. No common digit: The answer is a two-digit number formed from the minimum of each array, with the smaller digit in the tens place.
TestSmallestNumber — Seven test cases covering the key partitions: no common digit, common digit, single-element arrays, ordering when the smaller minimum is in nums2, multiple common digits, and fully overlapping arrays.
set(nums1) & set(nums2) is the idiomatic Python approach, O(n+m).min(a, b) in the tens place and max(a, b) in the ones place: min(a,b) * 10 + max(a,b).unittest.main() guarded by _name_.Imports: Only unittest from the standard library — no external dependencies.
Imported by: The test_solution.py file in the same directory, plus hundreds of other test files across the repo import unittest (the "Imported By" list in the prompt is actually listing files that import unittest, not this solution directly).
1. Compute the set intersection of nums1 and nums2.
2. If non-empty, return min(common) — the smallest shared digit.
3. Otherwise, find a = min(nums1) and b = min(nums2).
4. Return the two-digit number min(a,b) * 10 + max(a,b).
The entire function is branchless after the initial if — no loops beyond what min() and set operations do internally.
min(a,b) * 10 + max(a,b) always produces a valid two-digit number (11-99). A zero in either array would break the tens-place assumption.None. The function trusts its inputs match the problem constraints (non-empty arrays of unique digits 1-9). Empty arrays would cause min() to raise ValueError.