Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit aa73f79

Browse files
author
Ram swaroop
committed
largest sum contiguous sub array : comments added
1 parent 2b27f3a commit aa73f79

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/me/ramswaroop/arrays/LargestSumContiguousSubArray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public static int getLargestSumOfContiguousSubArray(int[] a) {
2020
int maxSum = 0, maxSumTillIndex = 0;
2121

2222
for (int i = 0; i < a.length; i++) {
23-
maxSumTillIndex += a[i];
23+
maxSumTillIndex += a[i]; // keep on adding elements
2424
if (maxSumTillIndex < 0) {
25-
maxSumTillIndex = 0;
25+
maxSumTillIndex = 0; // once the sum is less than 0 restart adding elements from next index
2626
} else if (maxSumTillIndex > maxSum) {
2727
maxSum = maxSumTillIndex;
2828
}

0 commit comments

Comments
 (0)