JavaEasyNumbers10 min

Sum the digits of an integer

Print the sum of the decimal digits of the absolute value of n. Follow the stated ordering and edge-case conventions exactly. Interviewers use this task to probe algorithm selection, invariants, and boundary handling.

Input

One signed integer n.

Output

Print the sum of the decimal digits of the absolute value of n.

Constraints

-2147483648 <= n <= 2147483647.

Example

Input

12345

Output

15

Example 2 input

1000000000

Output

1

This example exercises a further boundary or ordering case.

Public test cases (2)

  • Input

    12345

    Expected output

    15
  • Input

    -908

    Expected output

    17
Hints (2)
  1. Identify the state needed to avoid recomputing work for each element.
  2. Read into long before taking the absolute value, then repeatedly extract the last digit.

Target complexity: time O(d) · space O(1)

Your solution

Checking runner availability…

Reference solution

Sign in for solution
All Java programs