Smallest subarray from a given Array with sum greater than or equal to K | Set 2 | Function to find the smallest subarray sum greater than or equal to target ; Base Case ; If sum of the array is less than target ; If target is equal to the sum of the array ; Required condition ; Driver Code
def smallSumSubset ( data , target , maxVal ) : NEW_LINE INDENT if target <= 0 : NEW_LINE INDENT return 0 NEW_LINE DEDENT elif sum ( data ) < target : NEW_LINE INDENT return maxVal NEW_LINE DEDENT elif sum ( data ) == target : NEW_LINE INDENT return len ( data ) NEW_LINE DEDENT elif data [ 0 ] >= target : NEW_LINE INDENT return 1 NEW_LINE DEDENT elif data [ 0 ] < target : NEW_LINE INDENT return min ( smallSumSubset ( data [ 1 : ] ,   \ target , maxVal ) , 1 + smallSumSubset ( data [ 1 : ] ,   \ target - data [ 0 ] , maxVal ) ) NEW_LINE DEDENT DEDENT data = [ 3 , 1 , 7 , 1 , 2 ] NEW_LINE target = 11 NEW_LINE val = smallSumSubset ( data , target , len ( data ) + 1 ) NEW_LINE if val > len ( data ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( val ) NEW_LINE DEDENT