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!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow 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 Mar 2026
Contest runs March 3 - 31. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.