Skip to content

Commit 5ba1cff

Browse files
authored
Optimizing maxSum updation (#186)
* Optimizing maxSum updation compare maxSum with cummulativeSum only when cummulativeSum is greater than zero * Fixing linter error
1 parent bc3d69d commit 5ba1cff

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

Dynamic-Programming/KadaneAlgo.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ function KadaneAlgo (array) {
55
cummulativeSum = cummulativeSum + array[i]
66
if (cummulativeSum < 0) {
77
cummulativeSum = 0
8-
}
9-
if (maxSum < cummulativeSum) {
8+
} else if (maxSum < cummulativeSum) {
109
maxSum = cummulativeSum
1110
}
1211
}

0 commit comments

Comments
 (0)