mediumArrayDynamic Programming 0 views

Find the Maximum Length of Valid Subsequence I

A subsequence sub of nums with length x is called valid if it satisfies: Return the length of the longest valid subsequence of nums.

A subsequence sub of nums with length x is called valid if it satisfies:

Return the length of the longest valid subsequence of nums.

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

Find the Maximum Length of Valid Subsequence I diagram

Example 1

Input: nums = [1,2,3,4]

Output: 4

Explanation: The longest valid subsequence is [1, 2, 3, 4] .

Example 2

Input: nums = [1,2,1,1,2,1,2]

Output: 6

Explanation: The longest valid subsequence is [1, 2, 1, 2, 1, 2] .

Example 3

Input: nums = [1,3]

Output: 2

Explanation: The longest valid subsequence is [1, 3] .

Constraints

  • 2 <= nums.length <= 2 * 10^5
  • 1 <= nums[i] <= 10^7

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.