Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.

Create Largest_Sub_Array_Sum.py #147

Open
wants to merge 1 commit into
base: master
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
18 changes: 18 additions & 0 deletions Python/Largest_Sub_Array_Sum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from sys import maxint
def maxSubArraySum(a,size):

max_so_far = -maxint - 1
max_ending_here = 0

for i in range(0, size):
max_ending_here = max_ending_here + a[i]
if (max_so_far < max_ending_here):
max_so_far = max_ending_here

if max_ending_here < 0:
max_ending_here = 0
return max_so_far


a = [1,2,3,-9,52,-12,-13,-15,19,15,100,-99]
print "Maximum contiguous sum is", maxSubArraySum(a,len(a))