Skip to content

Instantly share code, notes, and snippets.

@thanhnguyentang
Last active January 11, 2016 02:17
Show Gist options
  • Select an option

  • Save thanhnguyentang/70576db10faad3603099 to your computer and use it in GitHub Desktop.

Select an option

Save thanhnguyentang/70576db10faad3603099 to your computer and use it in GitHub Desktop.
MAXIMUM-SUBARRAY(A, low, high)
sum = A[low]
left_index = low
right_index = low
right_sum = A[low]
start_index = low
for i = low+1 to high
if right_sum > 0
right_sum = right_sum + A[i]
else
right_sum = A[i]
start_index = i
if sum < right_sum
sum = right_sum
right_index = i
left_index = start_index
return left_index, right_index, sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment