← All mock interviewsHints used: 0
Minimum Size Subarray Sum Mock Interview
- ✓Problem→
- 2Clarifying Questions→
- 3Constraints→
- 4Brute Force→
- 5Complexity Analysis→
- 6Pattern Recognition→
- 7Optimized Solution→
- 8Implementation→
- 9Testing→
- 10Follow-Up→
- 11Evaluation
Problem
Given an array of positive integers nums and a positive integer k, return the length of the shortest contiguous subarray whose sum is greater than or equal to k. If no such subarray exists, return 0. The subarray must be contiguous — you may not skip elements.
Constraints
- 1 ≤ n ≤ 10^5
- 1 ≤ nums[i] ≤ 10^4
- 1 ≤ k ≤ 10^9
Example
in: nums = [2,3,1,2,4,3], k = 7
out: 2
Clarify
Before choosing anything: what would you ask the interviewer? What assumptions are you making? (Duplicates? Empty input? Value ranges? What to return when there is no answer?)