Unequal Elements (Also for Core/Database Intern :)
Learn this problemProblem statement
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.
Function
findMaxLength(skills: int[], k: int) → int
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🌷 ✩࿐⋆*
Examples
Example 1
skills = [1, 1, 2, 3, 2, 1]k = 2return = 5x = [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
1 ≤ n ≤ 2 * 1031 ≤ k < n1 ≤ skills[i] ≤ 2 * 103
More Snowflake problems
- Closest Target CharacterPHONE SCREEN · Seen Jul 2026
- Horizontal Pod AutoscalerSeen Jul 2026
- Minimum HeightOA · Seen Jul 2026
- Vowel SubstringSeen Jun 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Jun 2026
- Efficient DeploymentsOA · Seen Jun 2026
- Character Frequencies Across Nested String ListsPHONE SCREEN · Seen Jun 2026
- Character Frequencies Across StringsPHONE SCREEN · Seen Jun 2026