Company: Autodesk_14oct
Difficulty: medium
Alternating Digit Sum Problem Description Given an integer n , compute the alternating sum of its digits: take the leftmost digit as positive, the next digit as negative, the one after that as positive, and so on, alternating signs across the whole number. 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; }