JAVA Easy Solution Beats 100%
Intuition\n Describe your first thoughts on how to solve this problem. \nTo solve this problem, we need to minimize the sum of two numbers that can be formed by
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTo solve this problem, we need to minimize the sum of two numbers that can be formed by splitting the digits of the given 4-digit number. The best way to minimize the sum is by ensuring that the digits are distributed evenly between the two numbers we form.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Extract Digits: Start by extracting each digit from the 4-digit number. This can be done by repeatedly taking the remainder of the number divided by 10 and then updating the number by dividing it by 10.\n2. Sort Digits: Once all digits are extracted, sort them in ascending order. This ensures that the smallest digits are used to form the smaller numbers.\n3. Form Numbers: Create two numbers by pairing the smallest and largest remaining digits together. Specifically, form one number using the first and third smallest digits and the other number using the second and fourth smallest digits.\n4. Calculate Sum: Add these two numbers to get the minimum possible sum.\n\n\n\n\n# Complexity\n- Time complexity: O(1)\nThe operations involved (extracting digits, sorting a fixed number of 4 elements) are constant-time operations.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\nWe use a fixed-size array to store digits and a few extra variables, so the space complexity is constant.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int minimumSum(int num) {\n        int out[] = new int[4];\n        for(int i =0; i<out.length;i++){\n            out[i] = num % 10;\n            num = num /10;\n        }\n        Arrays.sort(out);\n        int result = ((out[0]*10) + out[2]) + ((out[1]*10) + out[3]);\n        return result;\n    }\n}\n```
['Math', 'Greedy', 'Sorting', 'Java']