Memory limit exceeded error in cpp code!


#1

void solution(vector &A,int index,vector<vector > &vc)
{
// vector<vector > vc;
if(index>=A.size()){return;}
if(index==A.size()-1)
{
vector vtt;
vc.push_back(vtt);
vtt.push_back(A[index]);
vc.push_back(vtt);
return;
}
solution(A,index+1,vc);
for(int i=0;i<vc.size();i++)
{
vector vtt=vc[i];
vtt.insert(vtt.begin(),A[index]);
vc.push_back(vtt);
}
// return vc;
}

vector<vector > Solution::subsets(vector &A)
{
vector<vector > vc;
sort(A.begin(),A.end());
solution(A,0,vc);
return vc;
}
goes here.