


For the given if N is 4 and K is 3,the possible combinations are [1,2,3] , [1,2,4] , [2,3,4],[1,3,4] .
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains two integers ‘N’ and ‘K’.
For each test case, print all the possible combinations in each line.
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 <= K <= N.
Time limit: 1 sec
In this approach, we will define a recursive function REC(‘IDX’, ’N’, ’K’, ’CUR’, ’ANS’) that will form all the possible combinations.IDX represents the current painting number.N represents the total number of paintings. K represents the number of paintings left to be added to the ‘CUR’ combinations and ‘ANS’ will store all possible combinations.
Base Cases:
If K is greater than (N-IDX+1), it implies that we have insufficient painting left to add them into the current combination. So return.
If K is equal to 0, it implies that the CUR combination is completed. Add that combination to ‘ANS’.
For each call, we have two choices either to add the ‘IDX’ picture into the combination or skip the ‘IDX’ painting.
In this approach, we will first declare an array ‘CUR’ of size ‘K’ and set all the values to 0. Then we will iterate the array using i from 0 to K-1 and set values as 1,2,3…K. When we reach the index K-1, it implies one combination. is completed. If the value of any index exceeds ‘N‘, we will jump back to the previous index and increase its value to create a new combination.
Sorted Doubly Linked List to Balanced BST
Longest Substring with K-Repeating Characters
Expression Add Operators
Gray Code Transformation
Count of Subsequences with Given Sum