Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Sliding window

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Sliding window

Minimum Size Subarray Sum

intermediatelayer B5 · Sliding window5 tests

Given an array nums of positive integers and a positive integer target, return the length of the shortest contiguous subarray whose sum is >= target.

  • If no such subarray exists, return 0
  • The subarray must be contiguous — you cannot cherry-pick elements
  • All values are positive, which is what makes a single sliding window work
  • Target complexity: O(n)

Example: target = 7, nums = [2,3,1,2,4,3] gives 2, from the subarray [4,3].

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen