MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / kadanes_algorithm

Function kadanes_algorithm

circular_kadne.py:1–9  ·  view source on GitHub ↗

Standard Kadane's Algorithm for maximum sum subarray.

(arr)

Source from the content-addressed store, hash-verified

1def kadanes_algorithm(arr):
2 """Standard Kadane's Algorithm for maximum sum subarray."""
3 max_ending_here = max_so_far = arr[0]
4
5 for num in arr[1:]:
6 max_ending_here = max(num, max_ending_here + num)
7 max_so_far = max(max_so_far, max_ending_here)
8
9 return max_so_far
10
11def max_circular_subarray(arr):
12 """Kadane's Algorithm variation for circular arrays."""

Callers 1

max_circular_subarrayFunction · 0.85

Calls 1

maxFunction · 0.50

Tested by

no test coverage detected