sum=0;
max=0;
for (i=0;i<n;i++){
sum+=a[i];
if (sum<0)
sum=0;
if (sum>max)
max=sum;
}
return max;
On Wed, Jun 30, 2010 at 8:25 PM, Raajay <[email protected]> wrote:
> Check out maximum contiguous subsequence problem. It is a very common
> dynamic programming problem and it uses O(1) space.
>
>
> On Wed, Jun 30, 2010 at 19:00, jalaj jaiswal <[email protected]>wrote:
>
>> You have an array of n nonzero numbers. The array is randomly filled with
>> positive and negative numbers.
>>
>> Write an algorithm/program to find 2 such indexes in the array, so as the
>> sum of the numbers between these indexes is the maximum. O(n).
>>
>> please explain the logic
>>
>> --
>> With Regards,
>> Jalaj Jaiswal
>> +919026283397
>> B.TECH IT
>> IIIT ALLAHABAD
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<algogeeks%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.