Given a list of integers, return a new list where each element is the cumulative sum of all elements from the beginning of the input list up to and including the current position. This is called a running total or prefix sum.

Return an empty list if the input is null or empty.

Examples:

Input: numbers = [1, 2, 3, 4] Output: [1, 3, 6, 10] Explanation: 1, 1+2=3, 1+2+3=6, 1+2+3+4=10 Input: numbers = [5] Output: [5] Explanation: Single element returns a single element list Input: numbers = [] Output: [] Explanation: Empty input returns empty list Input: numbers = [10, -3, 7] Output: [10, 7, 14] Explanation: 10, 10+(-3)=7, 7+7=14
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 November 2026 (Nov 16–30)Sponsored by FLXBL

Contest runs November 16 - 30. 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 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