In this HakerRank itertools.permutations() problem, we have given a string s. and we need to print all possible permutations of size k of the string in lexicographically sorted order.

HackerRank itertools.permutations() in python problem solution

HackerRank itertools.permutations() in python problem solution.

# Enter your code here. Read input from STDIN. Print output to STDOUT
from itertools import permutations
args = [x for x in raw_input().split()]
for i in list(permutations(sorted(args[0]), int(args[1]))):
    print (''.join(i))

Second Solution

from itertools import permutations
word = input().split()

text = ''.join(sorted(word[0]))
n = int(word[1])

premu = list(permutations(text,n))

for i in premu:
    print(''.join(i))