Minimum Length Subarray with Sum At Least N

Problem Find the minimum length of a contiguous subarray whose sum is >= n; return 0 if none exists.

Input / Output

  • Input: int array nums, int n. Output: min length or 0.

Constraints

  • Array up to 10^5; with positive integers O(n) is expected; ask whether negatives can appear — it changes the algorithm entirely.

Example

  • nums = [2,3,1,2,4,3], n = 7 → 2 ([4,3]).
asked …
LeaderboardSalaryAccount