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

Method helper

Backtracking/Homework/combinationSum.cpp:5–26  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3 vector<vector<int>> ans;
4
5 void helper(vector<int>& candidates, int target,int i,int curSum, vector<int> temp){
6 // Bounding Condition
7 if (curSum>target){
8 return;
9 }
10 // Base Condition
11 if (i==candidates.size()){
12 if(curSum==target){
13 ans.push_back(temp);
14 }
15 return;
16 }
17 // Inclusion
18 curSum+=candidates[i];
19 temp.push_back(candidates[i]);
20 helper(candidates,target,i,curSum,temp);
21 curSum-=candidates[i];
22 temp.pop_back();
23
24 // Exclusion
25 helper(candidates,target,i+1,curSum,temp);
26 }
27 vector<vector<int>> combinationSum(vector<int>& candidates, int target) {
28 vector<int> temp;
29 helper(candidates,target,0,0,temp);

Callers

nothing calls this directly

Calls 1

helperFunction · 0.70

Tested by

no test coverage detected