-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathKadaneAlgo.py
More file actions
35 lines (25 loc) · 759 Bytes
/
KadaneAlgo.py
File metadata and controls
35 lines (25 loc) · 759 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import math
class Solution:
def maxSubArraySum(self,arr,N):
##Your code here
max_ending=0
max_so_far=-math.inf
for i in range(N):
max_ending+=arr[i]
if max_so_far<max_ending:
max_so_far=max_ending
if max_ending<0:
max_ending=0
return max_so_far
import math
# Aditya Seth
def main():
T=int(input())
while(T>0):
n=int(input())
arr=[int(x) for x in input().strip().split()]
ob=Solution()
print(ob.maxSubArraySum(arr,n))
T-=1
if __name__ == "__main__":
main()