###Bug###
Bug
The first condition maxSoFar < array[i]
is wrong and should be removed. Otherwise a sequence such as 5 -10 6
will not find 6 as the max sum.
###Complicated expression###
Complicated expression
The other condition:
if (array[i] >= maxEndingHere + array[i]) {
is overly complicated. If you subtract array[i]
from both sides, you can simplify to:
if (maxEndingHere <= 0) {