JuniorArrayMath

Difference Between Element Sum and Digit Sum of an Array

You are given a positive integer array nums.

  • The element sum is the sum of all the elements in nums.
  • The digit sum is the sum of all the digits (not necessarily distinct) that appear in nums.

Return the absolute difference between the element sum and digit sum of nums.

Note that the absolute difference between two integers x and y is defined as |x - y|.

Example 1
Inputnums = [1,15,6,3]
Output9
The element sum is 25, the digit sum is 16, and the absolute difference is 9.
Example 2
Inputnums = [1,2,3,4]
Output0
The element sum is 10, the digit sum is 10, and the absolute difference is 0.

Constraints

  • 1 <= nums.length <= 2000
  • 1 <= nums[i] <= 2000

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate