Running Sum of an Array (Set 7)

Easy

Given an array of integers nums, return the running sum: index i of the result holds the sum of nums[0] through nums[i].

Running Sum of an Array (Set 7) — the data. This set runs 4 cases: nums holds arrays of 30–46 items, with values from -40 to 80. The hidden cases are the largest of the set.

Example 1

runningSum()
Input
nums = [58, 44, 77, 18, -30, 66, -6, 11, -25, 0, 24, 26, 3, 52, 15, 67, -31, 28, -11, -36, 75, 33, -35, 10, 35, -32, 27, 60, -23, 80, 28, 14, 16, -35, -33, 75, 4, -36, 5, 80, 25, -11, 49, 14, -2, -3]
Output
[58, 102, 179, 197, 167, 233, 227, 238, 213, 213, 237, 263, 266, 318, 333, 400, 369, 397, 386, 350, 425, 458, 423, 433, 468, 436, 463, 523, 500, 580, 608, 622, 638, 603, 570, 645, 649, 613, 618, 698, 723, 712, 761, 775, 773, 770]

Why

`runningSum` returns `[58, 102, 179, 197, 167, 233, 227, 238, 213, 213, 237, 263, 266, 318, 333, 400, 369, 397, 386, 350, 425, 458, 423, 433, 468, 436, 463, 523, 500, 580, 608, 622, 638, 603, 570, 645, 649, 613, 618, 698, 723, 712, 761, 775, 773, 770]` for this input.

Example 2

runningSum()
Input
nums = [-24, 31, 18, 68, 37, 76, 58, 7, 78, 53, 60, -17, -5, 16, 43, -11, -5, 2, -12, 31, 19, -9, 31, -19, 24, 21, 22, 29, 72, 10, 2, 70]
Output
[-24, 7, 25, 93, 130, 206, 264, 271, 349, 402, 462, 445, 440, 456, 499, 488, 483, 485, 473, 504, 523, 514, 545, 526, 550, 571, 593, 622, 694, 704, 706, 776]

Why

`runningSum` returns `[-24, 7, 25, 93, 130, 206, 264, 271, 349, 402, 462, 445, 440, 456, 499, 488, 483, 485, 473, 504, 523, 514, 545, 526, 550, 571, 593, 622, 694, 704, 706, 776]` for this input.
Constraints
1 <= nums.length <= 10^4
-10^3 <= nums[i] <= 10^3
Every case in this set must pass: the first two are visible on Run, the last two unlock on Submit.

Topics

ArraysPrefix Sum

Implement runningSum in the editor and return the answer — printing it is never graded.