Skip to content
Onsite

Digit Sum Array

EasyP3Coding

Return a new array of the same length where each element is replaced by the sum of its decimal digits. [123, 9, 40] becomes [6, 9, 4].

Example 1

Input
arr = [123,9,40]
Output
[6,9,4]

Example 2

Input
arr = [0]
Output
[0]

Example 3

Input
arr = [5]
Output
[5]

Constraints

  • 1 <= arr.length <= 10^5
  • 0 <= arr[i] <= 10^9

Hints

Run checks the 3 visible tests, Submit all 8.