#### Task

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.

#### Input Format

A single line containing the string *S* and integer value *k* separated by a space.

#### Constraints

**0 < ***k* < *len*(*S*)- The string contains only
*UPPERCASE* characters.

#### Output Format

Print the different combinations of string *S* on separate lines.

**Sample Input**

`HACK 2`

**Sample Output**

```
A
C
H
K
AC
AH
AK
CH
CK
HK
```

## itertools.permutations() Hacker Rank Solution in Python 2

```
from itertools import permutations
S,k = raw_input().split()
k = int(k)
print '\n'.join(sorted(''.join(p) for p in permutations(S,k)))
```

## itertools.permutations() Hacker Rank Solution in Python 3

```
# Enter your code here. Read input from STDIN. Print output to STDOUT
from itertools import permutations
s,n = input().split()
print(*[''.join(i) for i in permutations(sorted(s),int(n))],sep='\n')
```

## itertools.permutations() Hacker Rank Solution in pypy programming.

```
# Enter your code here. Read input from STDIN. Print output to STDOUT
from itertools import permutations
string_number = raw_input().split()
string = string_number[0]
number = map(int, string_number[1])
for elem in sorted(list(permutations(string, number[0]))):
n = len(elem)
elem_print = ""
for i in range(0, n):
elem_print+=elem[i]
print elem_print
```

### itertools.permutations() Hacker Rank Solution in pypy3

```
# Enter your code here. Read input from STDIN. Print output to STDOUT
import itertools
ll, n = input().split()
for i in itertools.permutations(sorted(ll),int(n)):
print("".join(i))
```

##### itertools.permutations() **Hacker Rank Solution Review:**

In our experience, we suggest you solve this itertools.permutations() Hacker Rank Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

itertools.permutations() problem is available on Hacker Rank for Free, if you are stuck anywhere between a compilation, just visit Queslers to get itertools.permutations() Hacker Rank Solution

**Conclusion:**

I hope this itertools.permutations() Hacker Rank Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Hacker Rank, Leetcode, Codechef, Codeforce Solution.

This Problem is intended for audiences of all experiences who are interested in learning Programming in a business context; there are no prerequisites.

Keep Learning!

**More Hacker Rank Problem & Solutions >>**

Staircase Hacker Rank Solution

A Very Big Sum Hacker Rank Solution

Diagonal Difference Hacker Rank Solution

Nested Lists Hacker Rank Solution

Lists Hacker Rank Solution