Alternating Index Square Sum
Updated
Problem statement
Given an integer array values, compute an alternating signed sum of squares:
- Add
values[i]^2wheniis even. - Subtract
values[i]^2wheniis odd.
Indexes are zero-based. Return the resulting 64-bit integer.
Function
alternatingSquareSum(values: int[]) → longExamples
Example 1
values = [1,2,3,4]return = -10The result is 1^2 - 2^2 + 3^2 - 4^2 = -10.
Example 2
values = [5]return = 25The only element is at even index 0, so its square is added.
Example 3
values = [-2,-3,4]return = 11Squaring removes the signs, so the result is 4 - 9 + 16 = 11.
Constraints
1 <= values.length <= 10^5.-10^6 <= values[i] <= 10^6.- The final result fits in a signed 64-bit integer.
More Accenture interview questions
- Nearest Composite NumberOA · Seen Sep 2026
- Minimum Password IncrementsOA · Seen Sep 2026
- Reduce a Number to One DigitOA · Seen Sep 2026
- Candy DistributionOA · Seen Sep 2026
- Customers Who Never OrderedOA · Seen Sep 2026
- Economical TripOA · Seen Sep 2026
- Coin ChangeOA · Seen Sep 2026
- Validate Email AddressOA · Seen Sep 2026
- Closest Rhyming WordOA · Seen Aug 2026
- Array Leader ElementsOA · Seen Nov 2025
Similar questions at other companies
- Confusing Bib NumbersVerily · ONSITE INTERVIEW
- Plus OneDruva · ONSITE INTERVIEW
- Rotate a Flat Image ClockwiseGoogle · ONSITE INTERVIEWGoogle interview questions
- Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
- Maximum Product of Three IntegersPelatro · ONSITE INTERVIEW
- Exact-Sixty Dice Game ValueJane Street · ONSITE INTERVIEWJane Street interview questions
- Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW
- Moving Cost by Volume and CategoryWayfair · ONSITE INTERVIEWWayfair interview questions
- Add One to a Number Represented as DigitsOracle · ONSITE INTERVIEWOracle interview questions
- Streaming Entropy, Part 1: Batch EntropyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions