Trains the technique from
LeetCode 3177Find the Maximum Length of a Good Subsequence IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Readings are given as nums. A pick takes some of them, keeping their order. A changeover is a place in the pick where a reading differs from the one directly before it.
Return the greatest number of readings a pick can hold while making at most k changeovers.
Example 1
Picking 7, 7, 2, 2 uses one changeover and holds four readings; picking 7, 2, 2, 2 also holds four. Taking a fifth reading would need a third changeover.
Example 2
Every reading differs from every other, so with no changeovers allowed a pick can hold only one.
Example 3
All the readings match, so the whole list is one pick with no changeovers.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def maximum_length(nums: list[int], k: int) -> int:public int maximumLength(int[] nums, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.