Warm-ups · 10 of 24
Running sum (prefix sums)
Return an array where each position holds the sum of all numbers up to and including that position.
Examples
Input nums = [1, 2, 3, 4]
Output [1, 3, 6, 10]
1, 1+2, 1+2+3, 1+2+3+4
Input nums = [3, -1, 2]
Output [3, 2, 4]
📘 New to this? Indexing and walking through an array explains the idea in a few minutes.
Solved it? The same idea on LeetCode: try it there ↗