Easiest on InterviewBit


#1

void solve(vector v,int l,int r,vector<vector > &out){
if(l==r)
{
out.push_back(v);
}
for(int i = l;i<=r;i++){
swap(v[i],v[l]);
solve(v,l+1,r,out);
swap(v[l],v[i]);

}
        return;

}

vector<vector > Solution::permute(vector &A) {
vector<vector > out;
solve(A,0,A.size()-1,out);
return out;
}