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 September 2026 (Sep 1–15)Sponsored by FLXBL

Contest runs September 1 - 15. Complete challenges to climb the leaderboard!

1st & 2nd: Salesforce certification exam voucher see all prizes

Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In