Tap here to switch tabs
Problem
Submissions

Problem: Find the Maximum Length of a Good Subsequence II

med
30 min
Try to solve the Find the Maximum Length of a Good Subsequence II problem.

Statement

You are given an integer array nums and a nonnegative integer k.

A sequence of integers sub is considered good if there are at most k indices i where 0≤i<0 \leq i < sub.length −1- 1 such that sub[i] != sub[i + 1].

Return the maximum possible length of a good subsequence of nums.

Note: A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

Constraints:

  • 1≤1 \leq nums.length ≤5imes103\leq 5 imes 10^3

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 0≤0 \leq k ≤min⁡(50,\leq \min(50, nums.length))

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find the Maximum Length of a Good Subsequence II

med
30 min
Try to solve the Find the Maximum Length of a Good Subsequence II problem.

Statement

You are given an integer array nums and a nonnegative integer k.

A sequence of integers sub is considered good if there are at most k indices i where 0≤i<0 \leq i < sub.length −1- 1 such that sub[i] != sub[i + 1].

Return the maximum possible length of a good subsequence of nums.

Note: A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

Constraints:

  • 1≤1 \leq nums.length ≤5imes103\leq 5 imes 10^3

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 0≤0 \leq k ≤min⁡(50,\leq \min(50, nums.length))