Created
August 16, 2021 20:04
-
-
Save Tamir198/63711bb5bb6cfc86ba5c562bad4826d8 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
function longestSuset(array) { | |
let arrLen = array.length; | |
let maxSubsetCount = new Array(arrLen).fill(1); | |
for (i = 1; i < arrLen; i++) { | |
for (j = 0; j < i; j++) { | |
if (array[i] > array[j] && maxSubsetCount[i] <= maxSubsetCount[j]) { | |
maxSubsetCount[i] = maxSubsetCount[j] + 1; | |
} | |
} | |
} | |
return Math.max.apply(null, maxSubsetCount); | |
}; | |
console.log(longestSuset([1, 3, 2, 4, 1, 1]));//Wanted output 3 | |
console.log(longestSuset([3, 0, 3, 1, 2, 3]));//Wanted output 4 | |
console.log(longestSuset([0, 9, 4, 8, 2, 10, 6]));//Wanted output 4 | |
console.log(longestSuset([0, 9, 4, 8, 2, 10, 6,12,1,2,3,4,0,6]));//Wanted output 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment