PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/IBM

Find minimum subarray length with k distinct integers

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's proficiency in array manipulation, distinct-element counting, and windowing techniques for optimizing contiguous-subarray queries. It is common in Coding & Algorithms interviews because it assesses algorithmic efficiency, the use of frequency-tracking data structures, and practical application-level problem solving rather than purely conceptual reasoning.

  • medium
  • IBM
  • Coding & Algorithms
  • Software Engineer

Find minimum subarray length with k distinct integers

Company: IBM

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given an integer array `arr` and an integer `k`, find the **minimum length** of a contiguous subarray that contains **exactly `k` distinct** integer values. Return the minimum length, or `-1` if no such subarray exists. Constraints/notes: - `arr` can contain duplicates. - A subarray is a contiguous slice of the array.

Quick Answer: This question evaluates a candidate's proficiency in array manipulation, distinct-element counting, and windowing techniques for optimizing contiguous-subarray queries. It is common in Coding & Algorithms interviews because it assesses algorithmic efficiency, the use of frequency-tracking data structures, and practical application-level problem solving rather than purely conceptual reasoning.

Related Interview Questions

  • Reverse last two characters with space - IBM (nan)
  • Compute minimum rooms for meeting schedule - IBM (nan)
  • Maximize palindromic strings after character swaps - IBM (medium)
  • Find minimum operations to make array sorted - IBM (easy)
  • Implement valid 1-D convolution - IBM (Medium)
IBM logo
IBM
Jan 31, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
4
0

Given an integer array arr and an integer k, find the minimum length of a contiguous subarray that contains exactly k distinct integer values.

Return the minimum length, or -1 if no such subarray exists.

Constraints/notes:

  • arr can contain duplicates.
  • A subarray is a contiguous slice of the array.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More IBM•More Software Engineer•IBM Software Engineer•IBM Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.