Problem 210831 · easy · Level 02 Linear Data Structures

Running Totals

arrays · prefix-sums · iteration

A rain gauge logs the millimetres of rain that fell each day in daily. Return a list where position i holds the total rainfall from day 0 up to and including day i.

Examples

Input:  daily = [1, 2, 3, 4]
Output: [1, 3, 6, 10]

Input:  daily = [5, 0, 0, 2]
Output: [5, 5, 5, 7]

Constraints

  • 0 <= len(daily) <= 10**5
  • -10**6 <= daily[i] <= 10**6
  • Target: O(n) time.

Goals

  • Accumulate a running sum
  • Build the prefix-sum list of a sequence
Starting Python…