Running Sum of 1d Array

Given an array nums, define its running sum as runningSum[i] = sum(nums[0]...nums[i]). Return the running sum of nums.

30:00

Running Sum of 1d Array
easy
Free written solution
Topics
Companies

Given an array nums, define its running sum as runningSum[i] = sum(nums[0]...nums[i]). Return the running sum of nums.

Example 1:
Input: {"nums":[1,2,3,4]}
Output: [1,3,6,10]
Constraints:
  • 1≤nums.length≤10001 \leq \text{nums.length} \leq 1000

  • −106≤nums[i]≤106-10^6 \leq \text{nums}[i] \leq 10^6

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums":[1,2,3,4]}

each number is a step; the running sum is the height you reach

010
[0]
1
.
[1]
2
.
[2]
3
.
[3]
4
.

Read each of the 4 numbers as a step up (positive) or down (negative). The running sum is the height after each step.

Variables
VariableValue
n4
DepthFunction Call
Stack empty
0/8