educative.io

Educative

Shorter solution in Python, works on lists with any elements

def find_kth_permutation(v, k):
    len_v = len(v)
    if len_v == 1:
        return v

    num_of_prev_perm = k // len_v
    prev_result = find_kth_permutation(v[1:], num_of_prev_perm)
    perm_pos = k % len_v
    result = prev_result[0:perm_pos] + [v[0]] + prev_result[perm_pos:]
    return result