| 5 | string s=""; |
| 6 | int c=0; |
| 7 | void calc(int n,int k,int m,vector<int > &v){ //m always decreases by 1 |
| 8 | if(m<0){ |
| 9 | return ; |
| 10 | } |
| 11 | |
| 12 | int d=fact[m];// factorial of m |
| 13 | |
| 14 | int x=ceil(k*1.0/d*1.0);// index of the element that has to be taken from vector |
| 15 | c=c*10 + v[x-1]; // forming the number |
| 16 | s=to_string(c); // converting number to string |
| 17 | v.erase(v.begin()+x-1); // now remove that digit as permutation has every digit once |
| 18 | int next_k=k-((x-1)*d); // finding the next k which is to be further processed with the same logic |
| 19 | calc(n,next_k,m-1,v); //its a recursive function |
| 20 | } |
| 21 | |
| 22 | |
| 23 | class Solution { |