FastPrepMinimum Length Good Subarray
Problems/Minimum Length Good Subarray

Minimum Length Good Subarray

Microsoft logoMicrosoft● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Microsoft intern online assessment. The report does not give limits on the numbers. Our version is about 99% the same as the reported question.

Given an array arr of n positive integers and an integer k, a contiguous subarray is good if it contains at least k distinct integers.

Return the minimum length of a good subarray. If no good subarray exists, return -1.

Function

findMinimumLengthSubarray(arr: int[], k: int) → int

Examples

Example 1

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

The full array and the subarray [2,1,1,3] each contain the three distinct integers 1, 2, and 3. The latter has length 4, and no shorter subarray contains all three values.

Constraints

  • 1 <= arr.length <= 10^5
  • 1 <= arr[i] <= 10^9
  • 1 <= k <= arr.length

More Microsoft Online Assessment questions

  • Authentication SystemOA · Seen Nov 2026
  • Maximum String OperationsOA · Seen Nov 2026
  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
  • Maximum Interactive Team SizeOA · Seen Nov 2026
  • Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
  • Minimum Cost K-Capable ModelsOA · Seen Nov 2026
  • Find Available Meeting RoomsOA · Seen Oct 2026

Similar questions at other companies

  • Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
  • Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
  • Count Subarrays with at Least K Equal-Fruit PairsTikTok · OATikTok interview questions
  • Consistent LogsRippling · OARippling interview questions
  • Auction Sniping Window MinimumCisco · OACisco interview questions
  • Balanced Prefix Sets in a PermutationUber · OAUber interview questions
  • Shortest Subarray Covering an Integer RangeMarshall Wace · OAMarshall Wace interview questions
  • Count Subarrays with at Least K Distinct ValuesVisa · OAVisa interview questions
  • Longest Frequency-Bounded SubarrayZipRecruiter · OAZipRecruiter interview questions
  • Find Subarray With Minimum Distinct IntegersAmazon · OA

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int findMinimumLengthSubarray(int[] arr, int k) {
      // Write your code here.
    }
}
Checking account…