Not so easy if you haven't done the previous questions. Solution is intuitive if you have


#1
`void combosum(vector<vector<int>>&C, vector<int>&A, vector<int> X, int B, int sum, int index){
    int i;
    //First element is pushed here
    X.push_back(A[index]);
    sum=sum+A[index];
    //If sum exceeds the desired value, return void
    if(sum>B)
        return;
    //If sum equals the desired value, push_back the vector into the 2-D vector
    if(sum==B){
        C.push_back(X);
    }
    //The next element after the previous element is controlled by this loop 
    for(i=index;i<A.size();++i){
        combosum(C,A,X,B,sum,i);
    }
}

vector<vector<int> > Solution::combinationSum(vector<int> &A, int B) {
    vector<vector<int>> C;
    vector<int> X, vec;
    
    //Sorting so that answer comes as expected output. Could also sort later.  
    sort(A.begin(),A.end());
    int i;
    //This is to remove any duplicate entries in the vector
    for(i=0;i<A.size()-1;++i){
        if(A[i]==A[i+1])
            continue;
        else 
            vec.push_back(A[i]);
    }
    vec.push_back(A[i]);
    //For the first element of each vector to be pushed into the 2-D vector
    for(i=0;i<A.size();++i){
        combosum(C,vec,X,B,0,i);
    }
    return C;
}
`