3177. Find the Maximum Length of a Good Subsequence II Hard

@problem@discussion
#Array#Hash Table#Dynamic Programming



1/**
2 * [3177] Find the Maximum Length of a Good Subsequence II
3 *
4 * You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1].
5 * Return the maximum possible length of a good <span data-keyword="subsequence-array">subsequence</span> of nums.
6 *  
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">nums = [1,2,1,1,3], k = 2</span>
10 * Output: <span class="example-io">4</span>
11 * Explanation:
12 * The maximum length subsequence is [<u>1</u>,<u>2</u>,<u>1</u>,<u>1</u>,3].
13 * </div>
14 * <strong class="example">Example 2:
15 * <div class="example-block">
16 * Input: <span class="example-io">nums = [1,2,3,4,5,1], k = 0</span>
17 * Output: <span class="example-io">2</span>
18 * Explanation:
19 * The maximum length subsequence is [<u>1</u>,2,3,4,5,<u>1</u>].
20 * </div>
21 *  
22 * Constraints:
23 * 
24 * 	1 <= nums.length <= 5 * 10^3
25 * 	1 <= nums[i] <= 10^9
26 * 	0 <= k <= min(50, nums.length)
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/find-the-maximum-length-of-a-good-subsequence-ii/
32// discuss: https://leetcode.com/problems/find-the-maximum-length-of-a-good-subsequence-ii/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn maximum_length(nums: Vec<i32>, k: i32) -> i32 {
38        0
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_3177() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.