Unequal Elements (Also for Core/Database Intern :)
A test needs to be prepared on the HackerRank platform with questions from different sets of skills
to assess candidates. Given an array, skills, of size n, where
skills[i] denotes the skill type of the ith question, select skills for the
questions on the test. The skills should be grouped together as much as possible. The goal is
to find the maximum length of a subsequence of skills such that there are
no more than k unequal adjacent elements in the subsequence. Formally, find a
subsequence of skills, call it x, of length m such that
there are at most k indices where x[i] != x[i+1] for all 0 ≤ i < m.
Complete the function findMaxLength in the editor.
findMaxLength has the following parameters:
- 1.
int skills[n]: the different skill types - 2.
int k: the maximum count of unequal adjacent elements
Returns
int: the maximum value of m
ᥫ᭡.🌷Credit to robot🌷 ✩࿐⋆*
1Example 1
x = [1, 1, 2, 2, 1].
There are only two indices where x[1] != x[2] and x[3] != x[4].
Return its length, 5.Constraints
Limits and guarantees your solution can rely on.
1 ≤ n ≤ 2 * 1031 ≤ k < n1 ≤ skills[i] ≤ 2 * 103