**Sheldon Password**

**Problem**

practice

**Tags: Permutation.**

**Author: Shami.**

This problem is a fancy way of asking to compute Kth permutation given a starting string. Since the maximum length of string is only 9, we can map the letters to digits and work with numbers (if that is more comfortable).

How to find the next permutation?

This Wiki article describes the following steps:

- Find the largest index k such that a[k] < a[k + 1]. If no such index exists, the permutation is the last permutation.
- Find the largest index l greater than k such that a[k] < a[l].
- Swap the value of a[k] with that of a[l].
- Reverse the sequence from a[k + 1] up to and including the final element a[n].

However, if you are programming in C++, youâ€™ll be happy to know there is a function that just does that!