Write an efficient C program to find the sum of contiguous subarray within a one-dimensional array of numbers which has the largest sum.
Approach : Kadene's Algorithm
Source: Wikipedia
Solution:
Here is the link to the ideone solution : http://ideone.com/howey4
Approach : Kadene's Algorithm
def max_subarray(A):max_ending_here = max_so_far = 0 for x in A: max_ending_here = max(0, max_ending_here + x) max_so_far = max(max_so_far, max_ending_here) return max_so_far
Source: Wikipedia
Solution:
Here is the link to the ideone solution : http://ideone.com/howey4
0 comments:
Post a Comment