Prefix sums
Inputs
values is a list of 0 to 14 whole numbers, each from -9 to 9.
Your tasks
- Create an empty list
prefixand a numberrunningthat starts at 0. - Use a loop over
values. Add each number torunning, then addrunningtoprefix. - Complete
prefixSumsso it returnsprefix. Return it, do not print it.
Example
With values = [3, -1, 4, 1], prefixSums returns [3, 2, 6, 7].
Rules
prefix[i]is the sum ofvalues[0]throughvalues[i].
Test data
TEST DATA 1: values is [3, -1, 4, 1]
TEST DATA 2: values is []
Practice focus
Prefix sums, counting, binary search, best stretch and sorting, all written as plain loops. This is where loops turn into named algorithms. You have already written the loops.