Easy Solution | Work 100% | Harshad Hiremath
\n\n# Intuition\nThe problem is to find the minimum sum that can be formed by dividing the digits of a 4-digit number into two two-digit numbers. To minimize th
![Screenshot 2024-08-07 004408.png](https://assets.leetcode.com/users/images/a0ce837c-475d-4f34-82ad-a0738640e26f_1722971672.7130806.png)\n\n# Intuition\nThe problem is to find the minimum sum that can be formed by dividing the digits of a 4-digit number into two two-digit numbers. To minimize the sum, you need to ensure that the two numbers formed are as small as possible. This can be achieved by sorting the digits and then combining them in a way that ensures minimal sums.\n\n# Approach\nConvert Number to Digits:\nConvert the given 4-digit number to a string to easily extract each digit.\n\nExtract Digits:\nConvert each character of the string back to an integer and store these digits in a vector.\n\nSort Digits:\nSort the vector of digits. Sorting helps in easily forming the smallest possible numbers from the digits.\n\nForm Two Numbers:\nAfter sorting, the smallest two-digit number can be formed by the first and third digits of the sorted list, and the second smallest two-digit number can be formed by the second and fourth digits.\n\nCalculate Minimum Sum:\nAdd these two numbers to get the minimum possible sum.\n\n# Complexity\n- Time complexity:\nThe time complexity is O(logn) due to the sorting operation, where \nn is the number of digits (in this case, n=4). Since n is constant, this is effectively O(1) for this specific problem. Extracting and converting the digits is O(1) as well\n\n- Space complexity:\nThe space complexity is O(1) because the space used does not grow with the input size but is instead constant. This includes the space used for the vector of digits.\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumSum(int num) {\n        string str=to_string(num);\n        vector<int> v;\n        for(char i:str)\n        {\n            v.push_back(i-\'0\');\n        }\n        sort(v.begin(),v.end());\n        int a=v[0]*10+v[2];\n        int b=v[1]*10+v[3];\n        return a+b;\n    }\n};\n```
['C++']