HackerRank Python - itertools.combinations()



You are given a string S.
Your task is to print all possible combinations, up to size k, 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
  3. s , n = input().split()
  4. for i in range(1, int(n)+1):
  5. for j in combinations(sorted(s), i):
  6. print (''.join(j))

download android app