Problems › Arrays & strings

Running Sum

Difficulty: Easy · Topic: Arrays & strings

Given an array nums, return its running sum, where result[i] = nums[0] + nums[1] + ... + nums[i].

Examples

running_sum([1,2,3,4])
→ [1,3,6,10]

1, 1+2, 1+2+3, 1+2+3+4.

running_sum([1,1,1,1,1])
→ [1,2,3,4,5]

Target complexity: time O(n), space O(n)

Write your solution in Python and run it against hidden tests right on this page. Progressive hints and Python + C++ reference solutions are included.

Learn the idea first: the lesson for this problem.

More Arrays & strings problems