kadane's algorithm cpp code example
Example: kadane's algorithm
def kadane(inputArray):
maxSum = float("-inf")
curSum = 0
for x in inputArray:
curSum = max(0, curSum + x)
maxSum = max(maxSum, curSum)
return maxSum
def kadane(inputArray):
maxSum = float("-inf")
curSum = 0
for x in inputArray:
curSum = max(0, curSum + x)
maxSum = max(maxSum, curSum)
return maxSum