Array ( [0] => [1] => questions [2] => Basic [3] => Upper-Row-Sum-Triangle )
Print the pattern as shown below for all test cases.
First line contains the value N.
Print the output as shown in below examples.
3
1 1 1 1 2 1
4
1 1 1 1 2 1 1 3 3 1
5
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
Login to see Discussion
Step-i) assign 1 to k and 0 to i
Step-ii) assign 1 to space
Step-iii) print space (" ") and increment the value of space by one value
Step-iv)repeat step iii till space is less than or equal to N-i
Step-v) assign 0 to j
Step-vi) if j is equal to 0 or i is equal to 0 assign 1 to k else assign k*(i-j+1)/j to k
Step-vii)print the value of k and space (" ") and increment j by one value
Step-viii)repeat steps vi and vii till j is less than or equal to i
Step-ix)go to next line and increment the value of i by one
Step-x)repeat the steps ii to ix till i is less than N
Time Complexity: O(n^2)
Space Complexity: O(1)
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution