Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
514 views

Can someone identify what is causing all test cases to return 'No' in my implementation of the subset sum problem?

def isSubls(l, n, s):

    if s == 0:
        return 'Yes'
    if n == 0 and s != 0:
        return False
    if l[n - 1] > s:
        return isSubls(l, n - 1, s)

    return isSubls(l, n-1, s) or isSubls(l, n-1, s-l[n-1])


def run():

    for _ in range(int(input())):

        n, m = map(int, input().split())
        l = []

        for i in range(n):
            l.append(int(input()))

        print(isSubls(l, n, m))


run()
 

in Coding Resources by Expert (500 points) | 514 views

Please log in or register to answer this question.

Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .