iq.lab
Python starts when a code cell comes near or you run one
easyLoops and basicsPrefix sums target 15 min

Running sum

Given a list of numbers nums, return a new list of the same length where the item at position i is the sum of nums[0] through nums[i].

Example 1
Inputnums = [1, 2, 3, 4]Output[1, 3, 6, 10]

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

Example 2
Inputnums = [3, -1, 2]Output[3, 2, 4]
Constraints
  • 0 ≤ len(nums) ≤ 105

  • -106 ≤ nums[i] ≤ 106

Plan it first

Write a line for each before you code, then say them out loud. Compare with the Approach tab afterwards.

⌘+Enter runs 0:00Python starts when a code cell comes near or you run one
Run examples checks the examples. Submit runs every test, including edge cases and, when the problem has one, a speed check on a large input.