class Solution { public: vector<vector<int> > combine(int n, int k) { vector<vector<int> > vv; vector<int> v; if(k<=0) return vv; if(k==1) { for(int k=1;k<=n;k++) {v.push_back(k); vv.push_back(v); v.clear(); } return vv; } return get_part(1,n,k); } vector<vector<int> > get_part(int m, int n,int k) { cout<<"enter"<<m<<" "<<n<<" "<<k<<" "<<endl; vector<vector<int> > vv; vector<vector<int> > vv1; vector<vector<int> > vv2; vector<int> v; if(k<=0) return vv; if(k>n) return vv; if(k==n) { for(int kk=1;kk<=n;kk++) { v.push_back(kk); } vv.push_back(v); return vv; } if(k==1) { //here is key for(int kk=1;kk<=n;kk++) {v.push_back(kk); vv.push_back(v); v.clear(); } for(int idx=0;idx<vv.size();idx++) { for(int idx_j=0;idx_j<vv[idx].size();idx_j++) cout<<vv[idx][idx_j]<<"---"; cout<<endl; } return vv; } int i=n; // for(int i=n;i>=k;i--) { vv2=get_part(m,i-1,k-1); for(int j=0;j<vv2.size();j++) { vv2[j].push_back(i); } for(int j=0;j<vv2.size();j++) vv.push_back(vv2[j]); vv1=get_part(m,i-1,k); for(int j=0;j<vv1.size();j++) vv.push_back(vv1[j]); } return vv; } };