FastPrepMinimum Size Subarray Sum
Problems/Minimum Size Subarray Sum

Minimum Size Subarray Sum

Microsoft logoMicrosoft● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This was the online assessment, the only step this author reached in a Microsoft software engineering internship process, per a review. The review gives a complete problem statement for a minimum-length subarray-sum question, including what to return when nothing qualifies.

The review gives the full rule. Only the limits are ours: 1 to 10^4 numbers, each from 1 to 10^4, and a target from 1 to 10^9. The platform is not named.

Our version is about 98% the same as the reported question.

Given an array of positive integers nums and a positive integer target, return the minimum length of a contiguous subarray whose sum is greater than or equal to target. If there is no such subarray, return 0.

Function

minSubArrayLen(target: int, nums: int[]) → int

Examples

Example 1

target = 9nums = [2,4,1,5,3,1]return = 3

No two neighbours add up to 9: the pairs give 6, 5, 6, 8 and 4. Three numbers are enough, for example [1, 5, 3] with sum 9, so the answer is 3.

Example 2

target = 20nums = [3,1,4]return = 0

All three numbers add up to only 8, which is less than 20, so no subarray works and the answer is 0.

Example 3

target = 4nums = [1,4,4]return = 1

The single number 4 already reaches the target, so the answer is 1.

Constraints

  • 1 <= target <= 10^9
  • 1 <= nums.length <= 10^4
  • 1 <= nums[i] <= 10^4

More Microsoft Online Assessment questions

  • 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
  • Maximum Sum of a K-StarOA · Seen Oct 2026
  • Capacity to Ship Packages Within DaysOA · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Longest Run of Ones After Flipping k ZerosC3.ai · PHONE SCREENC3.ai interview questions
  • Profit AnalysisVirtu Financial · OAVirtu Financial interview questions
  • Choose ContainersIMC Trading · OAIMC Trading interview questions
  • Calculate Total Distance TravelledAmazon · OA
  • TikTok Metrics AnalysisTikTok · OATikTok interview questions
  • Load BalancingMathWorks · OAMathWorks interview questions
  • Maximum Distinct Items Within a BudgetAdobe · OAAdobe interview questions
  • Size-Weighted Random Server PicksDocuSign · OADocuSign interview questions
  • Calculating QuantilesIndeed · OAIndeed interview questions
  • Count Lamps Lighting Each PointCapital One · OACapital One interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • 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, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        // Write your code here.
    }
}
Checking account…