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

Class Solution

Recursion/Homework/subsetSum.cpp:10–33  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected