Back to course home
0% completed
Solution: Shortest Subarray with Sum at Least K
Problem Statement
Given an array of integers nums
and a positive integer k
, return the minimum length
of the non-empty
subarray of nums
such that sum of its elements should be at least k
. If there is no
such subarray, return -1
.
A subarray is defined as a contiguous sequence
of an array.
Examples
-
Input: nums = [1, 2, 3, 4, 5], k = 11
Expected Output: 3
Justification: The shortest subarray with a sum of at least 11 is [3, 4, 5], which has a length of 3. -
Input: nums = [1, -1, 5, 2, 3, 4, 3, 2], k = 8
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible