#3300
Easy Algorithms Minimum element after replacement with digit sum
Array Math
84.7% acceptance
Feb 25, 2026
101
4
You are given an integer array nums.
You replace each element in nums with the sum of its digits.
Return the minimum element in nums after all replacements.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn min_element(nums: Vec<i32>) -> i32 {
nums.iter().map(|&n| {
let mut x = n;
let mut s = 0;
while x > 0 {
s += x % 10;
x /= 10;
}
s
}).min().unwrap()
}
}