Accepted in leetcode but not in interviewbit..what's wrong in my code?


#1

vector<vector> B;

vector<vector> subset(vector input,vector out,int i)
{
if(i==input.size()){
B.push_back(out);
return B;}
vector out1=out;
vector out2=out;
out2.push_back(input[i]);

subset(input,out1,i+1);
subset(input,out2,i+1);

return B;

}

vector<vector > Solution::subsets(vector &A) {
vector out;
subset(A,out,0);
sort(B.begin(),B.end());
return B;
}


#2

hey man you have to sort A not B :slight_smile:


#3

Thanks Helped me too.


#5


#6

1.try not to use global variable.
2. sort " out "every time before inserting into vector of vector int B