Skip to content

Practice Sum of Variable Length Subarrays

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#3427
LeetCode Problem

Sum of Variable Length Subarrays

Problem Statement

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.

Source: Sum of Variable Length Subarrays on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [2,3,1]
Output
11

# Example 2

Input
nums = [3,1,1,2]
Output
13

Constraints

1 <= n == nums.length <= 100
1 <= nums[i] <= 1000

Related LeetCode Problems

Practice more problems similar to Sum of Variable Length Subarrays.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.