-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Kadane's Algorithm #11840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kadane's Algorithm #11840
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
def maximumSubarraySum(arr): | ||
Check failure on line 1 in data_structures/arrays/KadaneAlgo.py
|
||
n = len(arr) | ||
maxSum = -1e8 | ||
Check failure on line 3 in data_structures/arrays/KadaneAlgo.py
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable and function names should follow the |
||
currSum = 0 | ||
Check failure on line 4 in data_structures/arrays/KadaneAlgo.py
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable and function names should follow the |
||
|
||
for i in range(0, n): | ||
Check failure on line 6 in data_structures/arrays/KadaneAlgo.py
|
||
currSum = currSum + arr[i] | ||
Check failure on line 7 in data_structures/arrays/KadaneAlgo.py
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable and function names should follow the |
||
if currSum > maxSum: | ||
maxSum = currSum | ||
Check failure on line 9 in data_structures/arrays/KadaneAlgo.py
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable and function names should follow the |
||
if currSum < 0: | ||
currSum = 0 | ||
Check failure on line 11 in data_structures/arrays/KadaneAlgo.py
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable and function names should follow the |
||
|
||
return maxSum | ||
|
||
|
||
if __name__ == "__main__": | ||
# Your code goes here | ||
arr = [1, 2, -54, 34, 22, 55, -22] # input your array here | ||
print(maximumSubarraySum(arr)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable and function names should follow the
snake_case
naming convention. Please update the following name accordingly:maximumSubarraySum
As there is no test file in this pull request nor any test function or class in the file
data_structures/arrays/KadaneAlgo.py
, please provide doctest for the functionmaximumSubarraySum
Please provide return type hint for the function:
maximumSubarraySum
. If the function does not return a value, please provide the type hint as:def function() -> None:
Please provide type hint for the parameter:
arr