It is simple. Here are the steps,
tot = sum of the entire array
max = tot
start = 0
end = n-1
sub_start = start
sub_end = end
while ( start < end )
{ if ( array[start] < array[end] )
{ tot=tot-array[start]
start++
}
else
{ tot=tot-array[start]
end--
}
if ( tot >= max )
{ max = tot
sub_start = start
sub_end = end
}
}
At the completion of the above code, you will get
sub_start = starting loaction of the subarray
sub_end = ending loaction of the subarray
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---