Longest Increasing Subsequence

Find the length of the longest increasing subsequence in an array using dynamic programming.

Code

Algorithms
const dp = new Array(arr.length).fill(1);
for (let i = 1; i < arr.length; i++) {
  for (let j = 0; j < i; j++) {
    if (arr[i] > arr[j]) dp[i] = Math.max(dp[i], dp[j] + 1);
  }
}
return Math.max(...dp);

Parameters

Array of numbers

Browser·fetch() may be limited by CORS

More JavaScript Snippets