Company: Autodesk_14oct
Difficulty: medium
Alternating Digit Sum Problem Description Given an integer n , your task is to calculate the alternating sum of its digits. In other words, add up all the digits, taking the first digit with a positive sign, the second digit with a negative sign, the third digit with a positive sign, etc. Examples Example 1: Input: n = 52134 Output: 5 Explanation: 5 - 2 + 1 - 3 + 4 = 5 Example 2: Input: n = 12345 Output: 3 Explanation: 1 - 2 + 3 - 4 + 5 = 3 Example 3: Input: n = 104956 Output: -5 Explanation: 1 - 0 + 4 - 9 + 5 - 6 = -5 Constraints Execution time limit: 0.5 seconds (cpp) Memory limit: 1 GB Input: integer n A positive integer number. Guaranteed constraints: 1 ≤ n ≤ 10 9 Output: integer The alternating sum of the digits of n . C++ Syntax Tips // prints help message to the console // Returns: "hello, <name>" string helloWorld(string name) { cout << "This prints to the console when you run Tests" << endl; return "hello, " + name; }