Minimum Element After Replacement With Digit Sum - Problem

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.

Input & Output

Example 1 — Basic Case
$ Input: nums = [10,12,13,14]
Output: 1
💡 Note: Replace elements: 10→1, 12→3, 13→4, 14→5. Array becomes [1,3,4,5]. Minimum is 1.
Example 2 — Larger Numbers
$ Input: nums = [1,2,3,4]
Output: 1
💡 Note: Single digit numbers remain unchanged: [1,2,3,4]. Minimum is 1.
Example 3 — Multi-digit Numbers
$ Input: nums = [999,191,22]
Output: 4
💡 Note: Replace elements: 999→27 (9+9+9), 191→11 (1+9+1), 22→4 (2+2). Array becomes [27,11,4]. Minimum is 4.

Constraints

  • 1 ≤ nums.length ≤ 100
  • 1 ≤ nums[i] ≤ 104

Visualization

Tap to expand
Minimum Element After Digit Sum ReplacementInput Array10121314Replace with digit sumsAfter Replacement13451+0=11+2=31+3=41+4=51Minimum
Understanding the Visualization
1
Input Array
Original integer array
2
Replace with Digit Sums
Each number becomes sum of its digits
3
Find Minimum
Return smallest digit sum
Key Takeaway
🎯 Key Insight: Transform each number to its digit sum and find the minimum in one efficient pass
Asked in
Meta 12 Google 8
12.0K Views
Medium Frequency
~10 min Avg. Time
450 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen