Skip to main content
Back to problems
Leetcode
Medium
Arrays
Dynamic Programming
Find The Maximum Length Of Valid Subsequence I

Find the maximum length of a subsequence that satisfies the problem's validity rule.

Acceptance 100%
Problem Statement

Given an integer array, choose a subsequence (not necessarily contiguous) whose elements satisfy the validity condition defined by the problem. Your task is to compute the maximum possible length of such a valid subsequence.

A subsequence keeps the original order of the chosen elements, but elements may be skipped. Among all valid subsequences, return the largest length that can be achieved.

Input Format

  • An integer array nums.
  • The exact validity rule is determined by the original problem statement.

Output Format

Return a single integer: the maximum length of a valid subsequence that can be formed from the array.

Constraints

  • The array may contain repeated values.
  • Preserve the original order of chosen elements.
  • The answer must be the maximum possible length among all valid subsequences.
Examples
Sample cases returned by the problem API.

Example 1

Input

nums = [1, 2, 3]

Output

3

Explanation

A valid subsequence can use all three elements if they satisfy the required condition.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.