Tap here to switch tabs
Problem
Submissions

Problem: Shortest Subarray with Sum at Least K

Shortest Subarray with Sum at Least K asks for the length of the shortest nonempty contiguous subarray whose sum reaches the target, even with negative values; return -1 if none exists.

Statement

Given an integer array nums and an integer k, return the length of the shortest non empty contiguous subarray of nums whose sum is at least k. If no such subarray exists, return -1.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −105≤-10^5 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq k ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Shortest Subarray with Sum at Least K

Shortest Subarray with Sum at Least K asks for the length of the shortest nonempty contiguous subarray whose sum reaches the target, even with negative values; return -1 if none exists.

Statement

Given an integer array nums and an integer k, return the length of the shortest non empty contiguous subarray of nums whose sum is at least k. If no such subarray exists, return -1.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −105≤-10^5 \leq nums[i] ≤105\leq 10^5

  • 1≤1 \leq k ≤109\leq 10^9