How to approach its solution?
Pascal Triangle!
Pascal’s triangle is the triangular array of the binomial coefficients.The number of entries in a given line is equal to the line number.Every entry in the line is the value of a binomial coefficient. The value of ith entry in the number line is C(line,i)(i.e apply mathematical combination formula ).
Where C(line,i)=line!/((line-i)!*i!).
Given pattern can be seen as first spaces then numbers and can be formed using 3 approches:
1.A simple method is to run two loops and calculate the value of binomial coefficient in inner loop. Complexity: O(N3).
2.O(N2) time and O(n2) space complexity.In this method store the previously generated values in 2-D array. Use these values to generate value in a line.
3.O(N2) time and O(1) space complexity. In this method calculate C(line,i) using C(line,i-1). It can be calculated in O(1) time as follows:
C(line,i-1)=line !/ ( ( line-i+1 ) ! * ( i-1) ! )
C(line,i)=line ! /( ( line-i ) ! * i ! )
C(line,i)=C(line,i-1) * ( line-i+1 )/ i .
still not able to get the approach completely.
Read this article.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
how to identify the spacing in the pattern shown??
@dsdishu99 before printing element in any row give spaces for column=1 to column =(n-row_no+1). then with every element print element+space.
it is not passing any test case
Hello @dsdishu99 you have raised the doubt again is there anything that you have not understood and i can help you with that.
please elaborate.
Happy Learning!!
@dsdishu99 i have corrected your code and commented the mistake:
if you have any doubt you can ask here:
Happy Learning!!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.