13 · Sliding Window

#209 Minimum Size Subarray Sum

Mediumsolve on LeetCode ↗

frequently reported atByteDance / TikTokBloombergMicrosoftAmazonMetaGoogle

the problem

In plain words

Given positive integers nums and a positive target, return the minimal length of a contiguous subarray whose sum is ≥ target, or 0 if none exists.

in target = 7, nums = [2,3,1,2,4,3]

out 2

[4,3].

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

out 1

[4] alone is enough.

in target = 11, nums = [1,1,1,1,1,1,1,1]

out 0

  • 1 ≤ target ≤ 10⁹
  • 1 ≤ n ≤ 10⁵
  • 1 ≤ nums[i] ≤ 10⁴

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #76
      Minimum Window Substring
      Hardin Sliding Window
    2. #862
    3. #560
      Subarray Sum Equals K
      Mediumin Hashing