Tap here to switch tabs
Problem
Submissions

Problem: Alternating Digit Sum

med
30 min
Try to solve the Alternating Digit Sum problem.

Statement

You are given a positive integer n. Each digit of n is assigned a sign that alternates between positive and negative:

  • The most significant digit is assigned a positive sign.

  • Each subsequent digit is assigned a sign opposite to the digit preceding it.

Return the sum of all digits with their corresponding signs applied.

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Alternating Digit Sum

med
30 min
Try to solve the Alternating Digit Sum problem.

Statement

You are given a positive integer n. Each digit of n is assigned a sign that alternates between positive and negative:

  • The most significant digit is assigned a positive sign.

  • Each subsequent digit is assigned a sign opposite to the digit preceding it.

Return the sum of all digits with their corresponding signs applied.

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9