Build Prefix Sums
Build the prefix sum list with a leading 0, so any range sum becomes one subtraction.
The problem
Implement build_prefix_aggregates(values). Return a list prefix of length len(values) + 1 where prefix[0] is 0 and prefix[i + 1] is the sum of values[0] through values[i]. For example, [3, -1, 4, 2] gives [0, 3, 2, 6, 8]. Do not change the input list.
Starter code
def build_prefix_aggregates(values):
passPublic examples
values = [3, -1, 4, 2]gives[0, 3, 2, 6, 8]values = [7]gives[0, 7]
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
