From 29a0d977d61aea13f5db27368118d7bf10177f99 Mon Sep 17 00:00:00 2001
From: DarkMoron <57228056+DarkMoron@users.noreply.github.com>
Date: Thu, 1 Oct 2020 17:11:45 +0530
Subject: [PATCH] Adding kadane's algorithm in Python

Kadane's algorithm is used to obtain the maximum contiguous subarray sum.
---
 lists/kadane's_algorithm.py | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 lists/kadane's_algorithm.py

diff --git a/lists/kadane's_algorithm.py b/lists/kadane's_algorithm.py
new file mode 100644
index 0000000..68628ed
--- /dev/null
+++ b/lists/kadane's_algorithm.py
@@ -0,0 +1,24 @@
+# Python program to find maximum contiguous subarray
+
+def maxSubArraySum(a,size): 
+	
+	max_so_far = 0
+	max_ending_here = 0
+	
+	for i in range(0, size): 
+		max_ending_here = max_ending_here + a[i] 
+		if max_ending_here < 0: 
+			max_ending_here = 0
+		
+		# Do not compare for all elements. Compare only 
+		# when max_ending_here > 0 
+		elif (max_so_far < max_ending_here): 
+			max_so_far = max_ending_here 
+			
+	return max_so_far 
+
+
+# Driver function to check the above function (with a sample test case)
+
+a = [3, 3, -25, 20, -3, 16, 23, -12, -5, 22, -15, 4, -7] 
+print "Maximum contiguous sum is", maxSubArraySum(a,len(a))