Sum of All Odd Length Subarrays Problem
Sum of All Odd Length Subarrays Problem — ExecCode Easy DSA Practice
Solve the Sum of All Odd Length Subarrays problem on ExecCode. Free online easy DSA practice in Math. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given an array of positive integers arr, return the sum of all possible odd-length subarrays of arr. Your task is to a subarray is a contiguous subsequence of the array. Return the required answer exactly as shown in the examples.
Examples
Input {"arr": [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110]}; Output 8760. Input {"arr": [2, 4, 6, 8, 10]}; Output 114. Input {"arr": [1, 2]}; Output 3
Constraints
1 <= arr.length <= 100 1 <= arr[i] <= 1000
Practice Sum of All Odd Length Subarrays free on ExecCode. Browse DSA problems, topic map, and placement guides.