In this HackerRank itertools.combinations() problem solution you are given a string and we need to print all possible combinations, up to size k of the string in lexicographically sorted order.


HackerRank itertools.combinations() in python problem solution

HackerRank itertools.combinations() problem solution


from itertools import combinations
(String, Value) = input().split()

String = sorted(String)
Value = int(Value)

for i in range(1,Value+1):
    for val in list(combinations(String,i)):
        print(''.join(val))