function longestIncreasingSubsequence(nums) {
const n = nums.length;
if (n === 0) return 0;
// Initialize an array of length n, filled with 1s, as the minimum length of any LIS is 1
const dp = Array(n).fill(1);
// Iterate through the elements in the nums array
for (let i = 1; i < n; i++) {
for (let j = 0; j < i; j++) {
// Check if the current element is greater than the previous one
if (nums[i] > nums[j]) {
// If it is, update the dp array with the maximum length found so far
dp[i] = Math.max(dp[i], dp[j] + 1);
}
}
}
// Find the maximum length of the LIS by iterating through the dp array
let maxLIS = dp[0];
for (let i = 1; i < n; i++) {
maxLIS = Math.max(maxLIS, dp[i]);
}
// Return the maximum length of the LIS
return maxLIS;
}