(a, size)
| 1 | #Program to find max subarray in python |
| 2 | def maxSubArraySum(a, size): |
| 3 | |
| 4 | |
| 5 | |
| 6 | max_so_far = 0 |
| 7 | |
| 8 | max_ending_here = 0 |
| 9 | |
| 10 | |
| 11 | |
| 12 | for i in range(0, size): |
| 13 | |
| 14 | max_ending_here = max_ending_here + a[i] |
| 15 | |
| 16 | if max_ending_here < 0: |
| 17 | |
| 18 | max_ending_here = 0 |
| 19 | |
| 20 | elif (max_so_far < max_ending_here): |
| 21 | |
| 22 | max_so_far = max_ending_here |
| 23 | |
| 24 | |
| 25 | |
| 26 | return max_so_far |
| 27 | |
| 28 | a=[] |
| 29 | n=int(input("size")) |