Skip to content

Commit a573f11

Browse files
authored
Merge pull request deutranium#66 from Ayushmanglani/master
Added Kadane's Algorithm
2 parents 758b61d + 8a6d3b5 commit a573f11

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
T = int(input())
2+
for _ in range(T):
3+
n = int(input())
4+
a = list(map(int, input().split()))
5+
maxglobal = -9999999999999999999
6+
max_here = 0
7+
8+
for i in range(0, n):
9+
max_here = max_here + a[i]
10+
if (maxglobal < max_here):
11+
maxglobal = max_here
12+
13+
if max_here < 0:
14+
max_here = 0
15+
print(maxglobal)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Kadane's algorithm
2+
3+
Used to find the sum of contiguous subarray within a one-dimensional array of numbers which has the largest sum.

0 commit comments

Comments
 (0)