Skip to the code
+10 XP

#38 Running Total of Sales

easy

A sales dashboard draws a cumulative chart: each point shows the total sales from the first day up to and including that day.

Write runningTotals(sales) that returns an array of the same length where item i is sales[0] + sales[1] + ... + sales[i].

Example 1

Input: sales = [3,1,4,1,5]
Output: [3,4,8,9,14]

Each number is the previous total plus that day's sales.

Example 2

Input: sales = []
Output: []

No days, no totals.

Constraints

  • 0 <= sales.length <= 2 * 10^5
  • -10^4 <= sales[i] <= 10^4
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).