Kadane algorithm is used to find: Maximum sum subsequence in an array Maximum sum subarray in an array Maximum product subsequence in an array code example
Example: max subsequence sum in array
def max_subarray(numbers):
"""Find the largest sum of any contiguous subarray."""
best_sum = 0 # or: float('-inf')
current_sum = 0
for x in numbers:
current_sum = max(0, current_sum + x)
best_sum = max(best_sum, current_sum)
return best_sum