Alternating Signed Digit Sum
Updated
Problem statement
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) → intExamples
Example 1
digits = "521"return = 4The result is 5 - 2 + 1 = 4.
Example 2
digits = "12345"return = 3The result is 1 - 2 + 3 - 4 + 5 = 3.
Constraints
1 <= digits.length <= 100000digitscontains 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