INPUT : K = 2
OUTPUT: 1 1
In the above example, K = 2, Hence the 2nd row from the top of pascalβs triangle, as shown in the above example is 1 1.
INPUT : K = 4
OUTPUT : 1 4 6 4 1
In the above example, K = 4, Hence the 4th row from the top of pascalβs triangle, as shown in the above example is 1 3 3 1.
The first line of input contains an integer 'T' representing the number of the test case. Then the test case follows.
The first and the only line of each test case contains a single integer βKβ.
For every test case, print a single line containing 'R' space-separated integers showing the Kth row of pascalβs triangle, where 'R' is the number of elements in a particular row.
The output of each test case will be printed in a separate line.
You donβt have to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 50
1 <= K <= 50
Where βTβ is the number of test cases, βKβ is the input row number.
Time limit: 1 sec.
In this approach, we find the row elements of the previous row using recursion, and based on the values of previous row elements, we will evaluate the current row elements.
In this approach, we will build our solution in the bottom-up manner storing the results in a 2D array βDPβ.
In this approach, we will try to observe the pattern and make the sequence for the current row elements. We can clearly see that the Kth row of pascalβs triangle has the sequence : C(K, 0), C(K, 1), ..., C(K, K - 1), C(K, K), where C(N, R) is the binomial coefficient or Combination function. As C(K, 0) = 1, we can evaluate other values of the sequence by the formula, C(N, R) = (C(N, R - 1) * (N - R )) / R .