Skip to content
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

kadanes algo #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions kadanes algo
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# defining the function to find the maximum subarray sum
def max_Subarray_Sum(my_array, array_size):
# assigning the variables
maxTillNow = my_array[0]
maxEnding = 0

# using the for-loop
for n in range(0, array_size):
maxEnding = maxEnding + my_array[n]
# using the if-elif-else statement
if maxEnding < 0:
maxEnding = 0

elif (maxTillNow < maxEnding):
maxTillNow = maxEnding

return maxTillNow
# defining the array
my_array = [-2, -3, 4, -1, -2, 5, -3]
# printing the maximum subarray sum for the users
print("Maximum Subarray Sum:", max_Subarray_Sum(my_array, len(my_array)))