Longest Subsequence

ARRAY

DYNAMIC PROGRAMMING

### Problem

Given an integer array `nums`

, return the length of the longest subsequence where the subsequence first strictly increases and then strictly decreases.

A subsequence is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements.

### Examples

`longestSubsequence([1, 2, 1]) // returns 3 // The longest subsequence is [1, 2, 1], // which increases and then decreases longestSubsequence([1, 8, 7, 4, 9, 3, 2]) // returns 6 // The longest subsequence is [1, 8, 7, 4, 3, 2], // which first increases to 8, then decreases to 2`

Loading...