Find the Smallest Value After One Digit-Sum Replacement
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
# Find the Smallest Value After One Digit-Sum Replacement
### Problem
You are given a positive integer array `nums`. Replace each element with the sum of the decimal digits of that original element, exactly once.
Return the minimum of the resulting values. A digit sum may itself have multiple digits; do not keep summing its digits.
### C++ Interface
```cpp
class Solution {
public:
int minElement(vector<int>& nums);
};
```
### Examples
#### Example 1
**Input:** `nums = [248,90,10000]`
**Output:** `1`
**Explanation:** The replacements are `[14,9,1]`, whose minimum is `1`.
#### Example 2
**Input:** `nums = [88,97,799]`
**Output:** `16`
**Explanation:** The replacements are `[16,16,25]`, whose minimum is `16`. The values `16` and `25` are not replaced again.
### Constraints
- `1 <= nums.size() <= 100`
- `1 <= nums[i] <= 10^4`
### Clarifying Questions
- Which number's digits are summed? The original value at each position.
- Must the result be a single digit? No, there is only one replacement per element.
- Is the transformed array returned? No, return only its minimum value.
### What a Strong Answer Covers
- Correct decimal digit sums for all original elements, including internal or trailing zeros.
- Exactly one replacement per element, even when the resulting sum has several digits.
- The returned minimum, behavior on a one-element array, and time and space bounds under the given value limit.
### Follow-up Questions
- How would repeatedly summing until one digit remained change the task?
- Is storing the whole transformed array necessary to return its minimum?
```hint Handle one original number
Work out its decimal digit sum independently of the other elements, then compare that one sum with the best result so far.
```
Overview: Find the minimum after replacing each positive integer with its decimal digit sum exactly once. Includes worked examples, a proof, and a C++ answer.