I wonder how to tackle such problem, to be more specific:
Given a set and an integer $k$, find the $n$th lexicographically smallest permutation (with repetitions allowed) of the set. We will say that the permutation is valid if its length is up to $k$ (inclusive).
Here's an example: $S$ = {a, b, c}, $k$ = 4, $n$ = 15
a aa aaa aaaa aaab aaac aab aaba aabb aabc aac aaca aacb aacc ab
Output should be: "ab" as it's the n-th lexicographically smallest permutation of length up to k of this set.
How to do this efficiently?