#3177

Find the Maximum Length of a Good Subsequence II

hard · 25.1% accepted · 142 likes · top 4%

array · hash table · dynamic programming

⊣ practice⊣ open on leetcode ↗

Description

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.

Solution