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 October 2026 (Oct 16–31)Sponsored by FLXBL

Contest runs October 16 - 31. Complete challenges to climb the leaderboard!

Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes

Only the 16 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