NewProject Coding is here — build features and fix bugs in real codebases with an AI assistantSee what's new

You are given an integer array elements. You may select any subsequence (i.e., delete zero or more elements without changing the order of the remaining elements).

Return the maximum possible length of a subsequence such that there are at most k adjacent pairs with different values. In other words, for a subsequence [x₀, x₁, …, xₘ₋₁], the number of indices i with 0 ≤ i < m - 1 and xᵢ ≠ xᵢ₊₁ must be at most k.

Test Cases
Input
Output
Expected