Shortest SubArray with sum at least K

All submissions for this problem are available.
Return the length of the shortest, nonempty, contiguous subarray of an Array, A
, with sum at least K
.
If there is no nonempty subarray with sum at least K
, return 1
.
Input Format
T
A_{1} A B C D E ...
K_{1}
A_{2} A B C D E ...
K_{2}
A_{3} A B C D E ...
K_{3}
...
Where
T
is the number of Arrays to be checked; A_{1}
, A_{2}
, A_{3}
, etc. are the Number of Elements in each Array; A
, B
, C
, D
, E
, etc. are the subsequent elements of that array; and K_{1}, K_{2}, K_{3}, etc. are the K
value (minimum sum of subarray) for each array.
Each new line is an individual input, and can be read with subsequent
input()
statements in Python (or any alternative command for other languages that reads from the Standard Input or STDIN
).Hint: To manipulate the numbers on the same line as an array, split the text input obtained, through a
' '
(single space), since all numbers are delimited with a space, with a function like split()
or an equivalent (depending on what language you use).
For each String received, immediately output the result to the
STDOUT
or Standard Output (eg. using print()
in Python), each on a new line.
Example Input
3 1 1 1 2 1 2 4 3 2 1 2 3
This implies that the input has
3
arrays. The first one has a length 1
with the Element [1]
and K = 1
, the second one has a length 2
with the Elements [1, 2]
and K = 4
, and the third array has a length 3
with the Elements [2, 1, 2]
and K = 3
.
Example Output
1
1
3
This implies,
 For array
[1]
, we could get the subarray,[1]
of length1
to get the minimum sum of1
.  For array
[1, 2]
, we could get no subarray, with the minimum sum of4
.  For array
[2, 1, 2]
, the shortest subarray,[2, 1, 2]
with the mnimum sum of3
, has the length3
.
Note:
1 <= A.length <= 50000
10 ^ 5 <= A[i] <= 10 ^ 5
1 <= K <= 10 ^ 9
Author:  mrigankpawagi 
Tags  mrigankpawagi 
Date Added:  11082019 
Time Limit:  50 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, JS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions