0% completed
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
Expected Output: 3
Justification: The shortest subarray with a sum of at least 8 is [5, 2, 3], which has a length of 2. -
Input: nums = [-1, -1, -2, -3], k = 2
Expected Output: -1
Justification: The shortest subarray with a sum of at least 2 is not exist in thenums
. So, the answer is-1
.
Try it yourself
Try solving this question here:
.....
.....
.....
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible