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.
Example 1:
Input: nums = [1,2,1,1,3], k = 2
Output: 4
Explanation:
The maximum length subsequence is [1,2,1,1,3].
Example 2:
Input: nums = [1,2,3,4,5,1], k = 0
Output: 2
Explanation:
The maximum length subsequence is [1,2,3,4,5,1].
Constraints:
1 <= nums.length <= 5 * 1031 <= nums[i] <= 1090 <= k <= min(50, nums.length)Solutions for this problem are being prepared.
Try solving it yourselfLeetCode was HARD until I Learned these 15 Patterns • Ashish Pratap Singh • 1,002,296 views views
Watch 9 more video solutions →Practice Find the Maximum Length of a Good Subsequence II with our built-in code editor and test cases.
Practice on FleetCode