this can done by dyanamic programming
At every point keep the maximum sum including the current element and
excluding the current element
At last the maimum will be max of both the maximum
pseudo code :
max1 = max2 = 0
for i in 1 to n
temp = max2
max1 = MAX(max1, max2+array[i])
max2 = MAX(temp,max1)
final_max = MAX(max1,max2)
--
Regards
Jitendra Kushwaha
MNNIT, 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].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.