Implement a function to find the longest increasing subsequence in an array.
HardProblem Statement
Implement a function to find the longest increasing subsequence in an array.
Sample Input
[ 10, 9, 2, 5, 3, 7, 101, 18 ]
Sample Output
4
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
// Find the longest increasing subsequence in an array
function longestIncreasingSubsequence(arr) {
// Initialize a dp array to store the length of subsequence up to each element
// Update the dp array by comparing each element with previous elements
}
console.log(longestIncreasingSubsequence([ 10, 9, 2, 5, 3, 7, 101, 18 ]));
Input
[ 10, 9, 2, 5, 3, 7, 101, 18 ]
Expected Output
4