# 60.permutation-sequence

## Statement

• Difficulty: Hard
• Tag: `递归` `数学`

1. `"123"`
2. `"132"`
3. `"213"`
4. `"231"`
5. `"312"`
6. `"321"`

``````输入：n = 3, k = 3

``````

``````输入：n = 4, k = 9

``````

``````输入：n = 3, k = 1

``````

• `1 <= n <= 9`
• `1 <= k <= n!`

The set `[1, 2, 3, …, n]` contains a total of `n!` unique permutations.

By listing and labeling all of the permutations in order, we get the following sequence for `n = 3`:

1. `"123"`
2. `"132"`
3. `"213"`
4. `"231"`
5. `"312"`
6. `"321"`

Given `n` and `k`, return the `kth` permutation sequence.

Example 1:

``````Input: n = 3, k = 3
Output: "213"
``````

Example 2:

``````Input: n = 4, k = 9
Output: "2314"
``````

Example 3:

``````Input: n = 3, k = 1
Output: "123"
``````

Constraints:

• `1 <= n <= 9`
• `1 <= k <= n!`

## Solution

``````from itertools import permutations

class Solution:
def getPermutation(self, n: int, k: int) -> str:
arr = range(1, n + 1)
res = list(permutations(arr))[k - 1]
return "".join(map(lambda x: str(x), res))
``````