FastPrepFind the Maximum Length of a Good Subsequence I (LC 3176 :)
Problems/Find the Maximum Length of a Good Subsequence I (LC 3176 :)

Find the Maximum Length of a Good Subsequence I (LC 3176 :)

Snowflake logoSnowflake● MediumINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an integer array nums and a non-negative integer k. A sequence of integers seq is called good if there are at most k indices i in the range [0, seq.length - 2] such that seq[i] != seq[i + 1].

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

Function

maxLengthGoodSubsequence(nums: int[], k: int) → int

Complete the function maxLengthGoodSubsequence in the editor.

maxLengthGoodSubsequence has the following parameters:

  1. 1. int[] nums: an array of integers
  2. 2. int k: a non-negative integer

Returns int: the maximum possible length of a good subsequence

🌷 All credits go to the incredible Lie ༊·° 𓇢𓆸

Examples

Example 1

nums = [1,2,1,1,3]k = 2return = 4

The maximum length subsequence is [1,2,1,1,3].

Example 2

nums = [1,2,3,4,5,1]k = 0return = 2

The maximum length subsequence is [1,2,3,4,5,1].

Constraints

  • 1 <= nums.length <= 500
  • 1 <= nums[i] <= 10^9
  • 0 <= k <= min(nums.length, 25)

More Snowflake interview questions

  • 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
  • Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
  • Maximum Points by Deleting ElementsIBM · OAIBM interview questions
  • Longest String ChainVisa · OAVisa interview questions
  • Maximum Points by Deleting ElementsWalmart · OAWalmart interview questions
  • Bitwise XOR SubsequencesJP Morgan Chase · OAJP Morgan Chase interview questions
  • Count Equal-Frequency SubsequencesExpedia · OAExpedia interview questions
  • Bitwise XOR SubsequencesGoldman Sachs · OAGoldman Sachs interview questions
  • Longest String ChainLinkedIn · OALinkedIn interview questions
  • Max LikesTikTok · OATikTok interview questions
  • Count Valid SequencesOpenAI · OAOpenAI 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 maxLengthGoodSubsequence(int[] nums, int k) {
      // write your code here
    }

}
Checking account…