Skip to content

Instantly share code, notes, and snippets.

@rahatarmanahmed
Created January 29, 2014 05:38
Show Gist options
  • Save rahatarmanahmed/8682437 to your computer and use it in GitHub Desktop.
Save rahatarmanahmed/8682437 to your computer and use it in GitHub Desktop.
Function to do max subsequence problem
maxSubSequence = (array) ->
max = currentMax = array[0]
begin = temp = end = 0
for i in [1..array.length]
if currentMax < 0
currentMax = array[i]
temp = i
else
currentMax += array[i]
if currentMax >= max
max = currentMax
begin = temp
end = i
return [max, begin, end]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment