Any help? it's working if i sort the Input otherwise it's not working why


#1

void generate(vector<vector > &ans, vector&A, int B, int sum, int curr, vector&dummy){
if(sum > B) return;
if(sum == B){
sort(dummy.begin(), dummy.end());
ans.push_back(dummy);
return;
}
for(int i = curr; i < A.size(); i ++){
dummy.push_back(A[i]);
generate(ans, A, B, sum + A[i], i , dummy);
dummy.pop_back();
}
}
vector<vector > Solution::combinationSum(vector &A, int B) {
vector<vector > ans;
//sort(A.begin(), A.end());
int sum = 0;
vectordummy;
generate(ans, A, B, 0, 0, dummy);
sort(ans.begin(), ans.end());
ans.erase(unique(ans.begin(), ans.end()), ans.end());
return ans;
}