#3427

Sum of Variable Length Subarrays

newbie · 140 · lc easy +13 · 85.5% accepted · 108 likes · top 97%

Description

You are given an integer array nums of size n. For each index i where 0 <= i < n, define a subarray starting at start = max(0, i - nums[i]) and ending at i.

Return the total sum of all elements across every subarray defined in this way.

Code

1
2
3