Alternating Digit Sum
Give each digit of n a sign: the leftmost digit is positive, and the signs alternate going right. Return the sum of the signed digits.
Example 1
n 521
returns 4
5 - 2 + 1 = 4.
Example 2
n 111
returns 1
1 - 1 + 1 = 1.
Constraints
1 <= n <= 10**9
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Armstrong NumberBeginner
- Base K to DecimalBeginner
- Collatz StepsBeginner
- Count DivisorsBeginner
- Decimal to Binary StringBeginner
- Digit Sum in Base KBeginner
- Digital RootBeginner
- Excel Sheet Column NumberBeginner