3202. Find the Maximum Length of Valid Subsequence II Medium

@problem@discussion
#Array#Dynamic Programming



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


Back
© 2025 bowen.ge All Rights Reserved.