#60

Permutation Sequence

candidate master · 1365 · lc hard +32 · verified · 52.3% accepted · 7,229 likes · top 42%

play →

Description

The integers 1 through n produce n! unique permutations in lexicographic order. Given n and k, return the string form of the kth such permutation.

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"

Code

1
2
3