Skip to content

Commit 59fc3df

Browse files
authored
1 parent 8182060 commit 59fc3df

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

arrays/MaxSumSubarray.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
static int maximumSumSubarray(int k, ArrayList<Integer> a,int n){
2+
3+
Deque<Integer> dq = new LinkedList<>();
4+
5+
int i=0, sum=0;
6+
for(; i<k; i++) {
7+
sum += a.get(i);
8+
dq.addLast(a.get(i));
9+
}
10+
11+
for(; i<n; i++) {
12+
dq.addLast(a.get(i));
13+
14+
int curSum = sum + a.get(i) - dq.removeFirst();
15+
if(curSum > sum) sum = curSum;
16+
}
17+
18+
return sum;
19+
}

0 commit comments

Comments
 (0)