MCPcopy Create free account
hub / github.com/chaharnishant11/CodeIn10DSA / Solution

Class Solution

Recursion/Code/subsetSum.py:4–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2# Given an array of non-negative integers, and a value sum, determine if there is a subset of the given set with sum equal to given sum.
3
4class Solution:
5 def helper(self,a,s,temp,index):
6 # Base Cases
7 if (index>=len(a)):
8 return False
9 if (s==temp):
10 return True
11 if (s<temp):
12 return False
13
14 # recursive calls
15 recCall1 = self.helper(a,s,temp+a[index],index+1)
16 recCall2 = self.helper(a,s,temp,index+1)
17
18 # small calculation
19 return (recCall1 or recCall2)
20
21 def isSubsetSum (self, N, arr, sum):
22 return self.helper(arr,sum,0,0)
23
24 # code here
25
26
27

Callers 1

subsetSum.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected