Created
April 15, 2020 22:55
-
-
Save piperchester/84bcbae66c0a2be6ebd5cc520155e0f4 to your computer and use it in GitHub Desktop.
Max subarray
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def find_max_subarray(arr): | |
| min_sum = max_sum = 0 | |
| for running_sum in itertools.accumulate(arr): | |
| min_sum = min(min_sum, running_sum) | |
| max_sum = max(max_sum, running_sum - min_sum) | |
| return max_sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment