I want to find out all the sum of continuous sub-array of length K
for a given array of Length n
given that k < n
. For example, let the given array be arr[6]={1,2,3,4,5,6}
and k=3
,then answer is (6,9,12,15)
.
It can be obtained as :
(1+2+3)=6,
(2+3+4)=9,
(3+4+5)=12,
(4+5+6)=15.
I have tried this using sliding window of length k
,but its time complexity is O(n)
.Is any solution which takes even less time such as O(log n)
.