Easy · Math

Sum of digits

Given an integer n, return the sum of its decimal digits, ignoring the sign (for example 12345 → 15 and −908 → 9 + 0 + 8 = 17).

Examples

Example 1

n = 12345

Output: sum = 15

Example 2

n = -908

Output: sum = 17

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Math problems