Skip to content

Kadanes_algorithm #1959

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

Merged
merged 8 commits into from
May 9, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update kadanes_algorithm.py
  • Loading branch information
Raj-Parekh24 authored May 8, 2020
commit 7b0d50c302e25d041887d2cfe5fee7bffb5a6a2a
15 changes: 0 additions & 15 deletions maths/kadanes_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,8 @@
def negative_exist(arr):

"""
checks whether the max value in -ve or not
eg :-
>>> negative_exist([-2,-8,-9])
-2
>>> negative_exist([-2,1,5,9])
0
so max element is negative i.e. -2
so answer is -2

and if max value is positive it will return 0
and then apply the kadane's algorithm
eg :-
arr = [2,8,-9]
positive number exist so it will return 0
"""
max=arr[0]
for i in arr:
Expand Down Expand Up @@ -49,9 +37,6 @@ def kadanes(arr):

>>> kadanes([2,3,-9,8,-2])
8

>>> kadanes([-1 ,-2 ,-3 ,-8 ])
-1
"""
if negative_exist(arr) < 0:
return negative_exist(arr)
Expand Down