FrontendChallenges is a collection of frontend interview questions and answers. It is designed to help you prepare for frontend interviews. It's free and open source.
Given an integer array nums, find the length of the longest strictly increasing subsequence.
Rules:
Subsequence can skip elements (doesn't need to be contiguous)
Must be strictly increasing (each number must be larger than previous)
Elements must maintain relative order from original array
Constraints:
1 ≤ nums.length ≤ 1000
-1000 ≤ nums[i] ≤ 1000
Examples:
// Example 1:
console.log(lengthOfLIS([9,1,4,2,3,3,7]));
// Output: 4
// Explanation: [1,2,3,7] is longest increasing subsequence
// Example 2:
console.log(lengthOfLIS([0,3,1,3,2,3]));
// Output: 4
// Explanation: [0,1,2,3] is one possible answer
Template
index.ts
export function lengthOfLIS(nums: number[]): number {
}
Info
Question
Given an integer array
nums
, find the length of the longest strictly increasing subsequence.Rules:
Constraints:
Examples:
Template
index.ts
index.test.ts