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 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.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In