Practice Find the Maximum Length of Valid Subsequence I
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given nums, find the longest subsequence for which all sums of neighboring selected elements have the same parity. Equivalently, (sub[i] + sub[i + 1]) % 2 must have one common value across all adjacent pairs. Preserve the original order of selected elements and return the maximum length.
Source: Find the Maximum Length of Valid Subsequence I on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [1,2,3,4]
4
# Example 2
nums = [1,2,1,1,2,1,2]
6
# Example 3
nums = [1,3]
2
Constraints
Related LeetCode Problems
Practice more problems similar to Find the Maximum Length of Valid Subsequence I.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.