def solution(n, k):
    if n == k:
        print(*nums)
    else:
        for i in range(n, k):
            nums[n], nums[i] = nums[i], nums[n]
            solution(n + 1, k)
            nums[n], nums[i] = nums[i], nums[n]


nums = [1, 2, 3]
solution(0, 3)

8cdd5c1f9d017b4092a7512404769604addb512a
<mask token>

def solution(n, k):
    if n == k:
        print(*nums)
    else:
        for i in range(n, k):
            nums[n], nums[i] = nums[i], nums[n]
            solution(n + 1, k)
            nums[n], nums[i] = nums[i], nums[n]


<mask token>

def solution(n, k):
    if n == k:
        print(*nums)
    else:
        for i in range(n, k):
            nums[n], nums[i] = nums[i], nums[n]
            solution(n + 1, k)
            nums[n], nums[i] = nums[i], nums[n]


<mask token>
solution(0, 3)

def solution(n, k):
    if n == k:
        print(*nums)
    else:
        for i in range(n, k):
            nums[n], nums[i] = nums[i], nums[n]
            solution(n + 1, k)
            nums[n], nums[i] = nums[i], nums[n]


nums = [1, 2, 3]
solution(0, 3)
