Login

Striver SDE Sheet Problems

Problem title

Difficulty

Avg time to solve

Reverse Pairs

Hard

50 mins

Ninja And Ladoos

Hard

10 mins

Detect the first node of the loop

Moderate

10 mins

Count Set Bits

Hard

15 mins

K-th Permutation Sequence

Moderate

15 mins

Ninja at the Gym

Moderate

10 mins

Calculate square of a number

Easy

15 mins

Combination Sum II

Moderate

30 mins

Find Pattern in String

Easy

10 mins

Z Algorithm

Hard

15 mins

Problem

Submissions

3

Avg. time to solve

15 min

Success Rate

85%

Problem Statement

```
If ‘N’ = 3 and ‘K’ = 4. Then all permutations for ‘N’ = 3 are “123”, “132”, “213”, “231”, “312”, “321”. So the 4-th permutation is “231”.
```

```
The first line of input contains an integer ‘T’ which denotes the number of test cases or queries to be run. Then the test cases follow.
The first line of each test case contains two single space-separated integers ‘N’ and ‘K’, respectively.
```

```
The only line of output contains a string of K-th permutation sequence of numbers from 1 to ‘N’.
Print the output of each test case in a separate line.
```

```
You are not required to print the expected output, it has already been taken care of. Just implement the function.
```

```
1 <= ‘T’ <= 100
1 <= ‘N’ <= 9
1 <= ‘K’ <= N!
Time Limit: 1 sec
```

```
2
2 1
3 6
```

```
12
321
```

```
For the first test case, ‘N’ = 2. So all permutations are “12”, “21”. Now ‘K’ = 1, so the 1st permutation is “12”.
For the second test case, ‘N’ = 3. So all permutations are “123”, “132”, “213”, “231”, “312”, “321”. Now ‘K’ = 6, so the 6th permutation is “321”.
```

```
2
4 3
1 1
```

```
1324
1
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code