Ctrl K

Numbers Versus Digits

Easy
You are given an array of non-negative integers values. Compute two totals: the sum of the numbers themselves, and the sum of all the digits used to write them (every digit of every number, repeats included). Return the absolute difference between the two totals.
Example 1
values=[24, 7, 100] → 117

The numbers add up to 24 + 7 + 100 = 131, the digits to 2 + 4 + 7 + 1 + 0 + 0 = 14, and the gap is 117.

Example 2
values=[5, 9] → 0

Single-digit numbers are their own digits, so the gap is 0.

Constraints
  • 1 ≤ len(values) ≤ 2000
  • 0 ≤ values[i] ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAdd One to a Digit Array EasyThe Lost Ticket EasyCorner Stamps on a Table EasyBest Product of Three EasyThe Biggest Triangle on the Board Easy
loading Python…
Input
values=[24, 7, 100]
Expected
117

Run checks the first 3 tests in your browser. Submit checks all 82 tests on the server, hidden ones included.