DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Sliding Window

Minimum Size Subarray Sum

**Problem Statement:** Given an array of positive integers `nums` and a positive integer `target`, return the minimal length of a contiguous subarray of which the sum is greater than or equal to `target`. If there is no such subarray, return `0` instead. **Hint / Expected Approach:** Sliding window expand/shrink **Edge Cases to Consider:** - (1) Target larger than total sum - (2) Single element equals target - (3) All elements equal target

Examples

Example 1
Input: 7, [2,3,1,2,4,3]
Output: 2
Example 2
Input: 4, [1,4,4]
Output: 1
Example 3
Input: 11, [1,1,1,1,1,1,1,1]
Output: 0

Constraints

  • ▪1 <= data.length <= 10^5
  • ▪Memory complexity must be O(1) or O(k)
  • ▪Ensure non-overlapping pointer access

Watch Out For Edge Cases

  • ▪Target larger than total sum
  • ▪Single element equals target
  • ▪All elements equal target
Frequently Asked At
GoogleAmazonMicrosoftTCS