Find subarray with maximum sum

Given an array of size n, containing positive and negative integers, find the longest sub-array such that the sum of the elements in the sub-array is the maximum.

For example,
Given array :
10, 8, -5, 1, -27, 5, 7, -5, 11
the sub array should be : 10, 8

Source : CLRS & this sample interview question

1 comment:

Madan Kumar said...

2D Kadane's algo question would have been more interesting than 1D.

 
Stats