mediumArrayDynamic Programming 0 views

Find the Maximum Length of Valid Subsequence II

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

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

Find the Maximum Length of Valid Subsequence II diagram

Example 1

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

Output: 5

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

Example 2

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

Output: 4

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

Constraints

  • 2 <= nums.length <= 10^3
  • 1 <= nums[i] <= 10^7
  • 1 <= k <= 10^3

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.