Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python sum of a subset

n,su = map(int,input().split())
A = list(map(int,input().split()[:n]))
s = []
for i in range(0,len(A)+1):
    for j in range(i+1,len(A)+1):
        s.append(A[i:j])
        
for k in s:
    if sum(k) == su:
        f = 1
        break
if f == 1:
    print("TRUE")  
else:
    print("FALSE")
 
PREVIOUS NEXT
Tagged: #python #sum #subset
ADD COMMENT
Topic
Name
1+3 =