from sys import maxint
def kadane(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
  
# Driver function to check the above function 
a = [-13, -3, -25, -20, -3, -16, -23, -12, -5, -22, -15, -4, -7]
print "Maximum  sum is", kadane(a,len(a))
 

@@ -1,309 +1,269 @@
-from sys import maxint%0Adef kadane(a,size):%0A      %0A    max_so_far = -maxint - 1%0A    max_ending_here =
+def Max_Kadane(nums):%0A        res, current_max = float(%22-inf%22),
  0
+ 
 %0A      
-%0A  
   for 
-i in range(0, size):%0A        max_ending_here = max_ending_here + a%5Bi%5D%0A        if (max_so_far %3C max_ending_here):%0A            max_so_far = max_ending_here%0A %0A        if max_ending_here %3C 0:
+number in nums: # Each step we decide if it's better to add the element or start over %0A            current_max = max(current_max + number, number)%0A            res = max(current_max, res)
 %0A   
@@ -271,34 +271,13 @@
     
+%0A
     
-max_ending_here = 0  %0A
     
@@ -287,18 +287,11 @@
 urn 
-max_so_far
+res
 %0A  %0A
@@ -338,16 +338,18 @@
 ction %0Aa
+rr
  = %5B-13,
@@ -408,48 +408,83 @@
 -7%5D%0A
+max_sum = Max_Kadane(arr)%0A
 print 
+(
 %22Max
-imum  sum is%22, kadane(a,len(a
+ contiguous subarray %7B%7D%22.format(max_sum
 ))%0A
- %0A

Update kadane.py