HackerRank Python - itertools.combinations_with_replacement()



You are given a string S.
Your task is to print all possible size K replacement combinations of the string in lexicographic sorted order.



  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. from itertools import combinations_with_replacement
  3. s,k=input().split()
  4. for i in combinations_with_replacement(sorted(s),int(k)):
  5. print ("".join(i))

download android app