Problem · Dynamic Programming
Find the Maximum Length of a Good Subsequence I (LC 3176 :)
See Snowflake hiring insights
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].
Return the maximum possible length of a good subsequence of nums.
Complete the function maxLengthGoodSubsequence in the editor.
maxLengthGoodSubsequence has the following parameters:
- 1.
int[] nums: an array of integers - 2.
int k: a non-negative integer
Returns
int: the maximum possible length of a good subsequence
🌷 All credits go to the incredible Lie ༊·° 𓇢𓆸
Examples
01 · Example 1
nums = [1,2,1,1,3] k = 2 return = 4
The maximum length subsequence is [1,2,1,1,3].
02 · Example 2
nums = [1,2,3,4,5,1] k = 0 return = 2
The maximum length subsequence is [1,2,3,4,5,1].
Constraints
1 <= nums.length <= 5001 <= nums[i] <= 10^90 <= k <= min(nums.length, 25)
More Snowflake problems
- Effective Role PrivilegesPHONE SCREEN · Seen May 2026
- Minimum Clicks Between Wiki PagesOA · Seen May 2026
- Minimum Index Distance Between Person and CakeOA · Seen May 2026
- Simple Array Rotation GameSeen Apr 2026
- Max Element Indexes After RotationsOA · Seen Mar 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Mar 2026
- Grid Traversal (Infrastructure Automation Internship)Seen May 2025
- Horizontal Pod Autoscaler (Infrastructure Automation Internship)Seen May 2025
public int maxLengthGoodSubsequence(int[] nums, int k) {
// write your code here
}
nums[1,2,1,1,3]
k2
expected4
sign in to submit