| 11 | //User function template for C++ |
| 12 | |
| 13 | class Solution{ |
| 14 | public: |
| 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. |
| 42 | int main() |
nothing calls this directly
no outgoing calls
no test coverage detected