MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / SubArray

Class SubArray

dynamic_programming/longest_sub_array.py:12–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12class SubArray:
13
14 def __init__(self, arr):
15 # we need a list not a string, so do something to change the type
16 self.array = arr.split(',')
17 print(("the input array is:", self.array))
18
19 def solve_sub_array(self):
20 rear = [int(self.array[0])]*len(self.array)
21 sum_value = [int(self.array[0])]*len(self.array)
22 for i in range(1, len(self.array)):
23 sum_value[i] = max(int(self.array[i]) + sum_value[i-1], int(self.array[i]))
24 rear[i] = max(sum_value[i], rear[i-1])
25 return rear[len(self.array)-1]
26
27
28if __name__ == '__main__':

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected