Skip to content

Instantly share code, notes, and snippets.

@nramirez
Created October 6, 2017 12:50
Show Gist options
  • Save nramirez/7c6ea6e9f5e67e4ca87ae53f07b07f76 to your computer and use it in GitHub Desktop.
Save nramirez/7c6ea6e9f5e67e4ca87ae53f07b07f76 to your computer and use it in GitHub Desktop.
Longest increasing subsecuence
let highest = [];
longest = (sequence) => {
var ordered = sequence.map(n => n);
ordered.sort((a, b) => a - b);
var matrix = {};
const length = ordered.length;
for (let i = 0; i < length; i++) {
for(let j = 0; j < length; j++) {
if(ordered[i] == sequence[j]) {
matrix[i,j] = matrix[i-1, j] + 1;
} else {
matrix[i,j] = matrix[i-1, j];
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment