FastPrepUnequal Elements (Also for Core/Database Intern :)
Problems/Unequal Elements (Also for Core/Database Intern :)

Unequal Elements (Also for Core/Database Intern :)

Snowflake logoSnowflake● HardINTERNOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Special thanks: robot shared this problem.

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. 1. int skills[n]: the different skill types
  2. 2. int k: the maximum count of unequal adjacent elements

Returns int: the maximum value of m

Examples

Example 1

skills = [1, 1, 2, 3, 2, 1]k = 2return = 5

The longest possible subsequence is 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

  • 1 ≤ n ≤ 2 * 103
  • 1 ≤ k < n
  • 1 ≤ skills[i] ≤ 2 * 103

More Snowflake interview questions

  • Minimum StackPHONE SCREEN · Seen Nov 2026
  • Design In-Memory File SystemPHONE SCREEN · Seen Nov 2026
  • Merge Two Binary TreesPHONE SCREEN · Seen Nov 2026
  • Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
  • Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
  • Parallel Courses IIIONSITE INTERVIEW · Seen Nov 2026
  • Safest Shortest Path Through a GridOA · Seen Nov 2026
  • Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
  • LFU CacheOA · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • At Most K Jumps with Quadratic Transition CostInfosys · OAInfosys interview questions
  • Largest Consistent Visiting GroupAuxoAI · OA
  • Delete K Subsets for Maximum ScoreRubrik · OARubrik interview questions
  • Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
  • Maximum Index-Weighted Sum with Disjoint SwapsVisa · OAVisa interview questions
  • Maximum Sum of HeightsVirtu Financial · OAVirtu Financial interview questions
  • Pressure-Isolation Shutdown OrderIntuit · OAIntuit interview questions
  • Get Minimum IncrementIBM · OAIBM interview questions
  • Jump Game with Prime-3 StepsUber · OAUber interview questions
  • Maximum Payout with Context SwitchesPhonePe · OAPhonePe interview questions

Snowflake interview experiences

  • Snowflake AI Coding Interview, Experienced Hires: 3 Experiences
All Snowflake interview questionsSee Snowflake hiring insights
Saved
class Solution {
    public int findMaxLength(int[] skills, int k) {
      // write your code here
    }

}
Checking account…