Company: Visa iit roorkee

Difficulty: medium

Problem Statement

Alternating Digit Sum Problem Description You are given a positive integer n . Assign a sign to every digit of n according to these rules: The leading (most significant) digit gets a positive sign. Every digit after that flips sign relative to the digit right before it. Return the total obtained by adding up all the digits with their assigned signs. Examples Example 1: Input: n = 521 Output: 4 Explanation: (+5) + (-2) + (+1) = 4. Example 2: Input: n = 111 Output: 1 Explanation: (+1) + (-1) + (+1) = 1. Example 3: Input: n = 886996 Output: 0 Explanation: (+8) + (-8) + (+6) + (-9) + (+9) + (-6) = 0. Constraints 1 <= n <= 10 9

More Visa iit roorkee OA questionsInterview experiences