MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / sumOddLengthSubarrays

Method sumOddLengthSubarrays

SumOfAllLengthSubarrays.java:2–11  ·  view source on GitHub ↗
(int[] arr)

Source from the content-addressed store, hash-verified

1class Solution {
2 public int sumOddLengthSubarrays(int[] arr)
3 {
4 int l=arr.length;
5 int sum=0;
6 for(int i=0;i<l;i++)
7 {
8 sum+=(((i+1)*(l-i)+1)/2)*arr[i];
9 }
10 return sum;
11 }
12}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected