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

🏆 All Time Leaderboard

Contest runs January 1, 1970 - December 31, 9999. Complete challenges to climb the leaderboard!

Points are calculated for challenges completed during the contest period.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In