Simple C++ Solution | Beginner Friendly | 0ms | beats 100%
In order to find the the minimum sum, the best way to do it is by creating two two-digits numbers.\n(Or 1 digit numbers as leading zeros are allowed)\nThe reaso
In order to find the the minimum sum, the best way to do it is by creating two two-digits numbers.\n(Or 1 digit numbers as leading zeros are allowed)\nThe reason for the same is pretty simple and straight forward. \nConsider the example : 9999\n9 + 999 = 1008\n99 + 99 = 198\n\n**Now while creating the two digits, in order to minimize the sum, we need to ensure that the** **smaller numbers are on tens place, while the larger nubers are kept on ones.**\n*Also, Note that the question mentions that "Leading Zeros are allowed."\nIf leading zeros weren\'t allowed, then the approach would have been different.*\n\nSo using simple mathematics(By dividing and taking modulus), we store 4 digits of the 4 digit number in a array.\nSort the array and return the sum of numbers\nnum1 = arr[0] * 10 + arr[2];\nnum2 = arr[1] * 10 + arr[3];\n**sum = num1 + num2 =  (arr[0] + arr[1]) * 10 + arr[2] + arr[3]**\n\nTime - O(1)\nSpace - O(1)\n\n**Code :**\n\n```\nclass Solution {\npublic:\n    int minimumSum(int num) {\n        int a[4] = {0};\n        a[0] = num % 10;\n        num /= 10;\n        a[1] = num % 10;\n        num /= 10;\n        a[2] = num % 10;\n        num /= 10;\n        a[3] = num % 10;\n        sort(a, a + 4);\n        return ((a[0] + a[1]) * 10 + a[2] + a[3]);\n    }\n};\n```\nHappy Coding:)\nPlease Upvote and Comment for any doubts!\n```
['Math', 'C']