3201. Find the Maximum Length of Valid Subsequence I Medium
1/**
2 * [3201] Find the Maximum Length of Valid Subsequence I
3 *
4 * You are given an integer array nums.
5 * A <span data-keyword="subsequence-array">subsequence</span> sub of nums with length x is called valid if it satisfies:
6 *
7 * (sub[0] + sub[1]) % 2 == (sub[1] + sub[2]) % 2 == ... == (sub[x - 2] + sub[x - 1]) % 2.
8 *
9 * Return the length of the longest valid subsequence of nums.
10 * 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.
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">nums = [1,2,3,4]</span>
15 * Output: <span class="example-io">4</span>
16 * Explanation:
17 * The longest valid subsequence is [1, 2, 3, 4].
18 * </div>
19 * <strong class="example">Example 2:
20 * <div class="example-block">
21 * Input: <span class="example-io">nums = [1,2,1,1,2,1,2]</span>
22 * Output: 6
23 * Explanation:
24 * The longest valid subsequence is [1, 2, 1, 2, 1, 2].
25 * </div>
26 * <strong class="example">Example 3:
27 * <div class="example-block">
28 * Input: <span class="example-io">nums = [1,3]</span>
29 * Output: <span class="example-io">2</span>
30 * Explanation:
31 * The longest valid subsequence is [1, 3].
32 * </div>
33 *
34 * Constraints:
35 *
36 * 2 <= nums.length <= 2 * 10^5
37 * 1 <= nums[i] <= 10^7
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/find-the-maximum-length-of-valid-subsequence-i/
43// discuss: https://leetcode.com/problems/find-the-maximum-length-of-valid-subsequence-i/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn maximum_length(nums: Vec<i32>) -> i32 {
49 0
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_3201() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.