Given a list of integers, return a new list where each element at index i is the sum of all elements from index 0 to i (inclusive) from the original list. This is also known as a prefix sum or cumulative sum. If the input is null, return null. If the input is empty, return an empty list.
Examples:
Input: nums = [1, 2, 3, 4]
Output: [1, 3, 6, 10]
Explanation: Running sum is calculated as [1, 1+2, 1+2+3, 1+2+3+4] = [1, 3, 6, 10]
Input: nums = [5]
Output: [5]
Explanation: Single element list returns the same element
Input: nums = []
Output: []
Explanation: Empty list returns empty list
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.