With the following array and value:
v = 50
a = [10, 20, 25, 10, 15]
I want to iterate through the array adding up the values until the sum of these values exceeds the variable v. And then I want to be able to return the index in the array where that occurred. so...
10 + 20 + 25 = 55 (which is the first point which the sum is greater that 'v') so index = 2
Thanks for your help
For the sum:
For the index, idea is the same - you use the memo as an array and keep the sum in the first element:
you need to look at the array after that