-
-
Save bhenry/388282 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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