For this Question: For a number N we have N! unique permutations. <b>A permutation is a sequence of integers from 1 to N of length N containing each number exactly once.</b>
For a positive integer X, <b>X! = 1 * 2 * 3 *...* X-1 * X</b>
Your task is to find the Kth smallest permutation when all possible permutations of size N are arranged in sorted order.Input contains only two integers, the value of N and K.

Constraints:-
1 <= N <= 10000
1 <= K <= min(N!,100000000)Print the Kth permutation in form of a string. i. e don't print spaces between two numbers.Sample Input:-
3 5

Sample Output:-
312

Explanation:-
All permutations of length 3 are:-
123
132
213
231
312
321

Sample Input:-
11 2

Sample Output:-
1234567891110, I have written this Solution Code: #include <bits/stdc++.h>
using namespace std;
int factorial(int n) {
        if (n > 12) {
            // this overflows in int. So, its definitely greater than k
            // which is all we care about. So, we return INT_MAX which
            // is also greater than k.
            return INT_MAX;
        }
        // Can also store these values. But this is just < 12 iteration, so meh!
        int fact = 1;
        for (int i = 2; i <= n; i++) fact *= i;
        return fact;
}

string getPermutationi(int k, vector<int> &candidateSet) {
        int n = candidateSet.size();
        if (n == 0) {
        return "";
        }
        if (k > factorial(n)) return ""; // invalid. Should never reach here.

        int f = factorial(n - 1);
        int pos = k / f;
        k %= f;
        string ch = to_string(candidateSet[pos]);
        // now remove the character ch from candidateSet. 
        candidateSet.erase(candidateSet.begin() + pos);
        return ch + getPermutationi(k, candidateSet);
}
    
string solve(int n, int k) {
        vector<int> candidateSet; 
        for (int i = 1; i <= n; i++) candidateSet.push_back(i);
        return getPermutationi(k - 1, candidateSet);
}

int main(){
    int n,k;
    cin>>n>>k;
    cout<<solve(n,k);
    
}, In this Programming Language: C++, Now tell me if this Code is compilable or not?