easyArraysPattern: Prefix Sum

Cumulative Array Sum Solution

Problem Statement

You are given an array of integers `scores`. Compute and return the cumulative sum after every index.

Examples

Example 1:
Input:[1, 2, 3, 4]
Output:[1, 3, 6, 10]
Explanation: Running total after each round
Example 2:
Input:[5, 1, 5, 7]
Output:[5, 6, 11, 18]
Explanation: Running total after each round

Constraints

  • 1 <= n <= 1000
  • -10^6 <= arr[i] <= 10^6
Time: O(N) Space: O(1)
Start from index 1, add the value of previous element to current element. Time O(N), Space O(1).

Run, Test & Submit Code

Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.

Solve on Interactive Workspace

Tested Solutions

No solution code is currently loaded.
Complete this code in the workspace editor.