New update is available. Click here to update.

Posted: 28 Jan, 2021

Difficulty: Moderate

```
In lexicographical order, combination/array ‘A’ comes before array ‘B’ if ‘A’ is the prefix of array ‘B’, or if none of them is a prefix of the other and at the first position where they differ integer in ‘A’ is smaller than the integer in ‘B’.
```

```
Let the array ‘Arr’ be [1, 2, 3, 1] and ‘target’ = 5. Then all possible valid combinations in lexicographical order are -:
(1, 1, 3)
(2, 3)
```

```
The first line of input contains an integer ‘T’ denoting the number of test cases.
Then the first line of each test case contains two space-separated integers ‘N’ and ‘target’ denoting the number of elements in ‘Arr’ and the ‘target'
The second line of each test case contains N space-separated integers the elements of array ‘Arr’.
```

```
For each test case, print all possible valid combinations in a separate line in the lexicographical order. Elements in each combination must be in non-decreasing order. Print a new line after each test case.
```

```
You do not need to print anything, it has already been taken care of. Just implement the given function.
```

```
1 <= T <= 10
1 <= N <= 20
1 <= Arr[i] <= 30
1 <= target <= 30
Time Limit: 1 sec
```

SIMILAR PROBLEMS

Best time to buy and sell stock

Posted: 2 Sep, 2022

Difficulty: Moderate

Best time to buy and sell stock II

Posted: 5 Sep, 2022

Difficulty: Moderate

Ninja And The Class Room

Posted: 19 Sep, 2022

Difficulty: Easy

Array Rotation

Posted: 21 Oct, 2022

Difficulty: Easy

Find The Single Element

Posted: 30 Oct, 2022

Difficulty: Easy

Categories:

Popular Courses: