← All problemsSign in

3176. Find the Maximum Length of a Good Subsequence I

LeetCodeArrayHash TableDynamic ProgrammingOpen on judge ↗

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]. Examp

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start