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

Class Solution

Recursion/Code/subsetSum.cpp:13–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11//User function template for C++
12
13class Solution{
14public:
15 bool helper (vector <int> a, int sum,int tempSum, int i){
16 //Base Cases
17 if (sum==tempSum){
18 return true;
19 }
20 if (sum<tempSum){
21 return false;
22 }
23 if (i>=a.size()){
24 return false;
25 }
26
27 //Recursive Calls
28 int recCall1 = helper(a,sum,tempSum+a[i],i+1);
29 int recCall2 = helper(a,sum,tempSum,i+1);
30
31 //Small Calculation
32 return recCall1 || recCall2;
33
34 }
35 bool isSubsetSum(vector<int>arr, int sum){
36 return helper(arr,sum,0,0);
37 // code here
38 }
39};
40
41// { Driver Code Starts.
42int main()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected