#3427

Sum of Variable Length Subarrays

easy · 85.5% accepted · 108 likes · top 97%

array · prefix sum

⊣ practice⊣ open on leetcode ↗

Description

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

Return the total sum of all elements from the subarray defined for each index in the array.

Solution