Magicsheet logo

Form Smallest Number From Two Digit Arrays

Easy
75%
Updated 6/1/2025

Asked by 1 Company

Form Smallest Number From Two Digit Arrays

What is this problem about?

The Form Smallest Number From Two Digit Arrays coding problem asks you to find the smallest number that contains at least one digit from nums1 and at least one digit from nums2. The input arrays contain unique digits from 1 to 9.

Why is this asked in interviews?

Tinkoff and other tech companies ask this "Easy" Array and Math interview pattern question as a warm-up. It tests your ability to break a problem down into simple logical cases. It evaluates whether you can identify the two possible scenarios for the smallest number and write a concise, bug-free solution.

Algorithmic pattern used

This problem uses Enumeration and Hash Table/Set logic. There are two distinct cases:

  1. Intersection: If the two arrays share any common digits, the smallest number is simply the smallest common digit (a single-digit number).
  2. No Intersection: If they share no digits, you must pick the smallest digit from nums1 and the smallest digit from nums2. Combine them into a two-digit number, putting the smaller of the two in the tens place.

Example explanation

nums1 = [4, 1, 3], nums2 = [5, 7, 3, 9]

  1. Find intersection: Both contain 3.
  2. Smallest common is 3. Result: 3.

nums1 = [3, 5, 2], nums2 = [7, 8]

  1. Intersection: None.
  2. Min of nums1: 2.
  3. Min of nums2: 7.
  4. Combine: smaller goes first -> 2 then 7. Result: 27.

Common mistakes candidates make

  • Always making two digits: Forgetting that if a digit exists in both arrays, a single-digit number satisfies the condition ("contains at least one digit from nums1 and nums2").
  • Wrong combination: Combining the two minimums in the wrong order (e.g., returning 72 instead of 27).
  • Over-complicating: Sorting both arrays entirely when you only need to find the minimums or the intersection.

Interview preparation tip

For small constraints (digits 1-9), using a boolean array or a Bitmask to represent sets is extremely fast and shows you know how to optimize constants.

Similar Questions