Given an array(list) of Integers & a Target.
Task is to "Find the MINIMUM LENGTH OF SUBARRAY whose sum is equal or greater to Target".
Example 1 :
Nums : [1,4,2,2,1,4]
Target : 5
Output : 2
Explanation : 5 can be achieved by adding elements of minimum SubArray (1 & 4).
Example 2 :
Nums : [10,5,11,24,32]
Target : 1000
Output : 0
Explanation : Since no such SubArray exists whose sum is equal or greater than 1000.
Example 3 :
Nums : [1,2,5,3,4,1,6,8]
Target : 7
Output : 1
Explanation : SubArray having single element i.e. 8 has more value than target , thus output is 1.
Example 4 :
Nums : [1,2,5,3,4,1,6]
Target : 7
Output : 2Input Format
A number n(representing number of elements) Ele1 Ele2 Ele3 ... Elen(n more integer inputs) A number Target NOTE : Input is handled for you.
Output Format
Find the MINIMUM LENGTH OF SUBARRAY whose sum is equal or greater to Target. (Output Format is handled for you.)
Constraints
1. 1 <= n(number of elements) <= 10^4 2. Integer.MIN_VALUE < Target < Integer.MAX_VALUE
Notice
Try First, Check Solution later
1. You should first read the question and watch the question video.2. Think of a solution approach, then try and submit the question on editor tab.3. We strongly advise you to watch the solution video for prescribed approach.Example
Input
6 1 4 2 2 1 4 5
Output
2