🔍 Minimum Digit Sum in an Array || Beats 100% || Java
✅ Intuition
The goal is to find the minimum sum of digits for all numbers in an array.
We iterate through each number, calculate its digit sum, and track the mi
### ✅ **Intuition**
- The goal is to **find the minimum sum of digits** for all numbers in an array.
- We iterate through each number, calculate its **digit sum**, and track the **minimum**.

---

### 🔥 **Approach**
1. **Compute digit sum for each number**:
   - Extract each digit using `temp % 10`.
   - Add it to `digitSum`.
   - Remove the last digit using `temp /= 10`.
   - Store the computed digit sum in the array.

2. **Find the minimum digit sum**:
   - Iterate through the updated array and find the smallest value.

---

### ⏱️ **Complexity Analysis**
- **Time Complexity**:  
  - **Digit Sum Calculation**: $$O(d)$$ per number (where `d` is the number of digits).  
  - **Finding the Minimum**: $$O(n)$$  
  - **Total Complexity**: $$O(n \cdot d)$$ (for standard numbers, `d` is small, making it close to $$O(n)$$)

- **Space Complexity**: $$O(1)$$ (in-place modification of `nums`)

---

### 🛠️ **Code**
```java
class Solution {
    public int minElement(int[] nums) {
        for (int i = 0; i < nums.length; i++){
            int temp = nums[i], digitSum = 0;
            while (temp != 0){
                digitSum += temp % 10;
                temp /= 10;
            }
            nums[i] = digitSum; // Replace number with its digit sum
        }

        int minSum = nums[0];
        for (int num : nums){
            if (num < minSum) minSum = num;
        }

        return minSum;
    }
}
```

---

### 📝 **Example Walkthrough**
#### **Example 1**
```java
Input: nums = [19, 82, 46]
Output: 8
Explanation:
- 19 → 1 + 9 = 10
- 82 → 8 + 2 = 10
- 46 → 4 + 6 = 8 (smallest)
```

#### **Example 2**
```java
Input: nums = [55, 32, 11]
Output: 2
Explanation:
- 55 → 5 + 5 = 10
- 32 → 3 + 2 = 5
- 11 → 1 + 1 = 2 (smallest)
```

---

### ✅ **Optimized & Clean Solution! 🚀**
['Java']