Sobes.tech
Junior — Senior

The smallest possible sum of two numbers formed from the digits of a four-digit number

livecode

Task condition

Given a four-digit integer value. The task is to split its digits into two groups (each containing at least one digit), arbitrarily permute the digits within each group, and form two new numbers from the resulting sequences. The goal is to find the minimum sum of these two numbers. Leading zeros are allowed, but each of the four digits must be used exactly once.

Example 1: Input: value = 2932 Output: 52 Explanation:

  • Digits: 2, 9, 3, 2.
  • Split and permute: 23 and 29.
  • Sum: 23 + 29 = 52.
  • This is the minimal possible sum (for example, 2 + 329 = 331 — larger).

Example 2: Input: value = 4009 Output: 13 Explanation:

  • Digits: 4, 0, 0, 9.
  • Split and permute: 4 and 009 (009 is equivalent to 9, as leading zeros do not affect the value).
  • Sum: 4 + 9 = 13.
  • This is the minimal possible sum (for example, 40 + 09 = 49 — larger).

Example 3: Input: value = 1000 Output: 1 Explanation:

  • Digits: 1, 0, 0, 0.
  • Split and permute: 1 and 000 (000 equals 0).
  • Sum: 1 + 0 = 1.
  • This is the minimal possible sum (for example, 10 + 00 = 10 — larger).