Set i and j and check if array from i to j - 1 gives sum <= x
for i in range ( 0 , len ( presum ) ) : NEW_LINE INDENT for j in range ( i + 1 , len ( presum ) ) : NEW_LINE INDENT arr1_sum = ( presum [ i ] + ( total_sum - presum [ j ] ) ) NEW_LINE if ( ( arr1_sum <= x ) and ( total_sum - arr1_sum ) <= x ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT DEDENT return False NEW_LINE