Complete the code to initialize the dp array with 1s for each element.
const dp = new Array(nums.length).fill([1]);Each element starts with a subsequence length of 1 (the element itself).
Complete the code to check if nums[j] is less than nums[i] to extend the subsequence.
if (nums[j] [1] nums[i]) {
We extend the subsequence only if nums[j] is smaller than nums[i].
Fix the error in updating dp[i] to the maximum length found so far.
dp[i] = Math.[1](dp[i], dp[j] + 1);
We want the longest subsequence, so use Math.max to update dp[i].
Fill both blanks to find the maximum length in dp array after processing.
const maxLength = dp.[1]((a, b) => a [2] b ? a : b);
Use reduce with > to find the maximum value in dp.
Fill all three blanks to complete the LIS function that returns the length of the longest increasing subsequence.
function lengthOfLIS(nums: number[]): number {
const dp = new Array(nums.length).fill([1]);
for (let i = 1; i < nums.length; i++) {
for (let j = 0; j < i; j++) {
if (nums[j] [2] nums[i]) {
dp[i] = Math.[3](dp[i], dp[j] + 1);
}
}
}
return dp.reduce((a, b) => a > b ? a : b);
}Initialize dp with 1, check if nums[j] < nums[i], and update dp[i] with Math.max.
