Easy to understand Solution with simplest function|| 100% BEATS
Proof 100% Beats\n\n\n# Intuition\nThe problem can be interpreted as transforming each number in the array into the sum of its digits and then finding the minim
# Proof 100% Beats\n![Screenshot 2024-10-16 002039.png](https://assets.leetcode.com/users/images/4bc4a612-a340-4614-8169-4af1895b7bfd_1729019698.9495056.png)\n\n# Intuition\nThe problem can be interpreted as transforming each number in the array into the sum of its digits and then finding the minimum of these transformed values. To solve this, we break the task into two parts:\n\n1. For each element in the array, replace it with the sum of its digits.\n2. Find the minimum element after this transformation.\n\n# Approach\n1. Sum of Digits Calculation:\nThe function sum(int n) computes the sum of digits of a given integer n. This is done by continuously extracting the last digit using the modulo operator (n % 10) and adding it to the total. We then reduce n by dividing it by 10 (n = n / 10) to remove the last digit.\n\n2. Transform Array:\nIn the minElement method, we iterate over the input array nums. For each element nums[i], we calculate its digit sum using the sum() function and replace the element with this value.\n\n3. Find Minimum:\nAfter transforming all elements of the array, we iterate over it again to find the smallest transformed value by using Math.min().\n\n# Summary\n- Time Complexity: O(n * log(m)), where n is the size of the input array and m is the largest number in the array.\n- Space Complexity: O(1), constant space used apart from the input array.\n\n# Complexity\n1. Sum of Digits Function: The function sum(int n) takes O(d), where d is the number of digits in n. For large integers, d can be approximated as log(n) since the number of digits grows logarithmically with n.\n\n2. Transform Array: We traverse the array of length n and for each element, we compute the sum of digits. So, the overall complexity of this step is O(n * log(m)), where n is the size of the array, and m is the maximum number in the array (log(m) is the time for sum of digits).\n\n3. Finding Minimum: The second loop just scans through the array to find the minimum value, which is O(n).\n\nThus, the total time complexity is:\n\nO(n * log(m)), where n is the number of elements in the array and m is the maximum number in the array.\n\n# Space complexity:\nThe space complexity is O(1), as we are modifying the input array in place and using only a few extra variables (total, a, min). No additional space is used apart from the input array, so the space complexity is constant\n\n# Code\n```java []\nclass Solution {\n    public int sum(int n){\n        int total = 0;\n        while(n > 0){\n            total += n%10;\n            n = n/10;\n        }\n        return total;\n    }\n    public int minElement(int[] nums) {\n        int n = nums.length;\n        for(int i=0; i<n; i++){\n            int a = sum(nums[i]);\n            nums[i] = a;\n        }\n        \n        int min = Integer.MAX_VALUE;\n        for(int i=0; i<n; i++){\n            min = Math.min(min, nums[i]);\n        }\n        return min;\n    }\n}\n        \n    \n```
['Array', 'Math', 'Iterator', 'Java']