bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 2605. Form Smallest Number From Two Digit Arrays

2605. Form Smallest Number From Two Digit Arrays

Leetcode Solutions

Finding the Smallest Number with Digits from Two Arrays

  1. Initialize a variable smallest_common to a high value (e.g., 10) which is outside the range of digits.
  2. Iterate through nums1 and for each digit, check if it is present in nums2. If it is, update smallest_common to the smaller of its current value and the digit.
  3. If smallest_common is less than 10, return smallest_common as the result.
  4. If no common digit is found, find the smallest digit in nums1 and nums2 separately.
  5. Form two numbers by concatenating the smallest digits in different orders.
  6. Return the smaller of the two numbers formed in step 5.
UML Thumbnail

Brute Force Search for Smallest Number from Two Arrays

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...