Minimum Sum of Four Digit Number After Splitting Digits

To solve this problem, you can follow the steps below:

  1. Convert the number into a string and sort it in non-decreasing order.
  2. Create two numbers from the sorted digits by appending digits alternatively to each number. Since the digits are sorted, this ensures that both numbers are the smallest possible.
  3. Convert the two created strings back to integers and return their sum.

Python solution:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
class Solution:
    def minimumSum(self, num: int) -> int:
        # Convert the number to string and sort it
        num = sorted(str(num))

        # Create two numbers
        num1, num2 = '', ''
        for i in range(len(num)):
            if i % 2 == 0:
                num1 += num[i]
            else:
                num2 += num[i]

        # Convert the numbers to integers and return their sum
        return int(num1) + int(num2)

This solution works by minimizing the values of the two numbers created from the digits of the given number. By sorting the digits and distributing them evenly between the two numbers, we ensure that both numbers are as small as possible, thus minimizing their sum.