Array ( [0] => [1] => questions [2] => Arrays [3] => Consecutive-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 2 3 4 5 6
4
1 2 3 4 5 6 7 8 9 10
5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Login to see Discussion
Step-i) assign 1 to k
Step-ii) assign 1 to i
Step-iii)assign 1 to j
Step-iv)print k and increment its value by one
Step-v)increment j by one value
Step-vi)repeat steps iv and v till j is less than or equal to i
Step-vii)increment i by one value
Step-viii) repeat steps iii to vii till i is less than or equal to 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