You need to write an algorithm for finding the minimum sum of a continuous sequence of n numbers in an array of size m Example: arr=[5, 7, 2, 3, 5, 12, 1, 1, 5](m=9) with n=2, the answer is[1 , 1] with n=3 answer -[1, 1, 5].

There are options?

## 1 Answers

3

```
function getMinSum(arr, n) {
var
sum=0,
minSum=0,
index=0;
for(var i=0;i<n;i ++) {
sum +=arr[i];
}
minSum=sum;
for(var i=n;i<arr.length;i ++) {
sum=sum - arr[i - n] + arr[i];
if(sum<minSum) {
minSum=sum;
index=i - n + 1;
}
}
return {
sum: minSum,
seq: arr.slice(index, index + n)
};
}
```

What is it like? – Muddy21 Aug 21 '18 at 21:21