Given an array of positive integers arr, return the sum of all possible odd-length subarrays of arr. A subarray is a contiguous subsequence of the array.
Given an array of positive integers arr, return the sum of all possible odd-length subarrays of arr. A subarray is a contiguous subsequence of the array.
Example 1:
Input: {"arr":[1,4,2,5,3]}
Output: 58
Constraints:
1≤arr.length≤100
1≤arr[i]≤1000
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"arr":[1,4,2,5,3]}
Instead of listing every odd-length subarray, ask how many of them contain each element, then add element times that count.
14253
each cell will be one (start, end) choice; green cells have odd length