Skip to content

Instantly share code, notes, and snippets.

@bhenry
Forked from iwhcoj/findlongestsequence
Created May 3, 2010 16:29
Show Gist options
  • Save bhenry/388282 to your computer and use it in GitHub Desktop.
Save bhenry/388282 to your computer and use it in GitHub Desktop.
//pseudo code beloew
array = 1 2 3 4 1 2 3 4 5 1 2 3
//should print at the end 1 2 3 4 5 with count 5
max = 1
maxstart = 0
maxend = 0
for x = 0 ; x < array.length; x++
for j = x + 1 ; array[j] > array [j-1]: j++
if j - x + 1 > max: //we have a new longest subset
max = j - x + 1 //makes max inclusive on both ends
maxstart = x
maxend = j
//after j loop, don't bother checking x's between x and j.
x = maxend + 1 //this will start the next subseq as the one starting after the current max
//outside of the x loop
print ("the sequence is: ")
for i = maxstart ; i <= maxend ; i++
print (array[i] + " ")
print ("and is " + max + " long")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment