Accumulate Numeric Value Objects
Updated
Problem statement
Implement an accumulation over numeric value objects.
For this exercise, assume each object wraps one signed integer and adding two objects creates a value object whose amount is the exact sum of their amounts. Start with an amount of 0, add the objects represented by values from left to right, and return the final amount as a signed 64-bit integer.
An empty array returns 0. In languages with operator overloading, the wrapper may define addition directly; otherwise, give it an equivalent addition method.
Function
accumulateValues(values: int[]) → longExamples
Example 1
values = [2,3,-1]return = 4The running amounts are 0, 2, 5, 4, so the result is 4.
Example 2
values = []return = 0No objects are added, so the initial amount 0 remains.
Example 3
values = [1000000000,1000000000,1000000000]return = 3000000000Three amounts of 1000000000 sum to 3000000000, which exceeds a signed 32-bit integer.
Constraints
0 <= values.length <= 5000.-1000000000 <= values[i] <= 1000000000.
More Squarepoint Capital interview questions
- Mutable Record Store with Error ResultsONSITE INTERVIEW · Seen Sep 2026
- Maximum SubarrayONSITE INTERVIEW · Seen Aug 2026
- Product of Array Except SelfONSITE INTERVIEW · Seen Aug 2026
- Estimate Pi with a Finite SeriesONSITE INTERVIEW · Seen Oct 2025
- In-Memory Directory and File OperationsONSITE INTERVIEW · Seen Oct 2025
- Count C++ Constructor and Assignment CallsONSITE INTERVIEW · Seen Jun 2025
- Observe a Lazy GeneratorONSITE INTERVIEW · Seen Feb 2025
- Order Matching on ExecuteONSITE INTERVIEW · Seen Dec 2024
- Differentiate a PolynomialONSITE INTERVIEW · Seen Aug 2023
- Newton Square Root to a Guaranteed TolerancePHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Shuffle With Given Random DrawsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Plus OneDruva · ONSITE INTERVIEW
- Ring Buffer OperationsAmazon · ONSITE INTERVIEW
- Rotate a Flat Image ClockwiseGoogle · ONSITE INTERVIEWGoogle interview questions
- Matrix MultiplicationeBay · ONSITE INTERVIEWeBay interview questions
- Maximum Product of Three IntegersPelatro · ONSITE INTERVIEW
- Apply Overridden Integer TransformsOptimus Information · ONSITE INTERVIEWOptimus Information interview questions
- Exact-Sixty Dice Game ValueJane Street · ONSITE INTERVIEWJane Street interview questions
- Find the Missing Number from 1 to nHyperVerge · ONSITE INTERVIEW