2026-01-07 15:39:17 +0300 MSK

Permutation Sequence

Code

import itertools

class Solution:
    def getPermutation(self, n: int, k: int) -> str:
        for nums in itertools.permutations(range(1, n + 1), n):
            if k == 1:
                return "".join(map(str, nums))
            k -= 1
        raise Exception