values. Each element values[i] marks out its own window: it starts values[i] positions to the left (but never before the start of the array, so at index max(0, i - values[i])) and ends at element i itself, inclusive.
Add up each of these windows and return the grand total.values=[1, 4, 2] → 13
Index 0: window [1] = 1. Index 1: the value 4 reaches past the start, so the window is [1, 4] = 5. Index 2: two steps back, window [1, 4, 2] = 7. Total 13.
values=[2, 1, 1, 3] → 14
The windows are [2] = 2, [2, 1] = 3, [1, 1] = 2 and [2, 1, 1, 3] = 7, for 14 in total.
values=[1, 4, 2]
13
Run checks the first 3 tests in your browser. Submit checks all 92 tests on the server, hidden ones included.