FunctionRacerProblemsRace

Alternating Digit Sum

BeginnerMathPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems