Minimum Element After Replacement With Digit Sum

You are given an integer array `nums`. Replace every element of `nums` with the sum of its digits. Return the minimum element of `nums` after all replacements.

30:00

Minimum Element After Replacement With Digit Sum
easy
Free written solution
Topics
Companies

You are given an integer array nums.

Replace every element of nums with the sum of its digits.

Return the minimum element of nums after all replacements.

Example 1:
Input: {"nums":[10,12,13,14]}
Output: 1
Constraints:
  • 1≤nums.length≤1001 \leq nums.length \leq 100

  • 1≤nums[i]≤1041 \leq nums[i] \leq 10^4

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums":[10,12,13,14]}

best starts at infinity. Each of the 4 numbers will be squashed into the sum of its digits, and best keeps the smallest sum.

x -> sum of digits of x

10

·

12

·

13

·

14

·

best

∞

Variables
VariableValue
n4
bestinf
DepthFunction Call
Stack empty
0/9