Given a string or collection of elements, find the kth permutation of them. For ex, if "123" is the given string then following are their permutations in order: "123", "132", "213", "231", "312", "321".
One obvious way to solve the problem is by enumerating all the permutations and eventually stopping when we get to the requested permutation. The approach is brute force as in the worst case it takes up-to O(n!) - for ex, if the requested permutation is n!th one or >n!.
Problem can be solved if we skip enumerating all permutations, and get to the required one by using factorials. Below is the corresponding code for the same. I have also posted the brute force one for convenience.