FastPrepAlternating Signed Digit Sum
Problems/Alternating Signed Digit Sum

Alternating Signed Digit Sum

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A ZipRecruiter new-grad OA report describes reading decimal digits left to right, adding the digits at even zero-based positions and subtracting the digits at odd positions. The report leaves out limits and a function signature, so our version supplies those details.

You are given a nonempty decimal string digits. Read it from left to right using zero-based positions.

Add digits at even positions and subtract digits at odd positions. Return the resulting signed sum.

Function

alternatingDigitSum(digits: String) → int

Examples

Example 1

digits = "521"return = 4

The result is 5 - 2 + 1 = 4.

Example 2

digits = "12345"return = 3

The result is 1 - 2 + 3 - 4 + 5 = 3.

Constraints

  • 1 <= digits.length <= 100000
  • digits contains only decimal digits.

More ZipRecruiter Online Assessment questions

  • Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
  • Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
  • Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
  • Minimum Changes to Draw a YOA · Seen Oct 2024
  • Apply Binary State OperationsOA · Seen Sep 2024
  • Simulate Orchard Rot SpreadOA · Seen Sep 2024
  • Compare Odd- and Even-Index SumsOA · Seen Sep 2024
  • Coordinate Removals with Column GravityOA · Seen Sep 2024
  • Lexicographically Smallest End ReversalOA · Seen Sep 2024
  • Recursively Expanded Shell Command CountsOA · Seen Sep 2024

Similar questions at other companies

  • Identification Number Check DigitAbridge · OAAbridge interview questions
  • Count Substrings With Identical CharactersVirtu Financial · OAVirtu Financial interview questions
  • Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions
  • Is This Date a Weekend?Salesforce · OASalesforce interview questions
  • Triple-Position Alphabet EncodingArm · OA
  • Closest ColorTwo Sigma · OATwo Sigma interview questions
  • Prime Number From a StringAdobe · OAAdobe interview questions
  • Sum Integer StringsIntuit · OAIntuit interview questions
  • Digit Changes for a Multiple of 9Nutanix · OANutanix interview questions
  • Count Times Using at Most Two DigitsLSEG · OALSEG interview questions

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public int alternatingDigitSum(String digits) {
        // Write your code here.
    }

}
Checking account…